Skip to content

Commit

Permalink
clap commands parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jenna-a2ai committed Mar 22, 2024
1 parent d38ddc3 commit ba90c2d
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 9 deletions.
179 changes: 179 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
# git-discover = "0.13.1"
clap = {version = "4.4.17", features = ["derive"]}
22 changes: 22 additions & 0 deletions src/cmd/init_cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::internal::git::repo;
use crate::internal::storage::init;
use std::path::PathBuf;

fn get_init_runner(storage_dir: &PathBuf, mode: u32, gid: u32) -> Result<(), std::io::Error> {

let git_repo = match repo::get_nearest_repo_dir(storage_dir) {
Ok(git_repo) => {
// json
git_repo
}
Err(e) => {
// json
return Err(e)
}
};

let init_run = init::init(&git_repo, &storage_dir, &mode, &gid);



}
2 changes: 1 addition & 1 deletion src/internal/git/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn is_git_repo(dir: &PathBuf) -> bool {
dir.join(".git").is_dir()
}

pub fn get_nearest_repo_dir(dir: PathBuf) -> Result<PathBuf, std::io::Error> {
pub fn get_nearest_repo_dir(dir: &PathBuf) -> Result<PathBuf, std::io::Error> {
let mut directory = match dir.canonicalize() {
Ok(directory) => directory,
Err(e) => return Err(e)
Expand Down
2 changes: 1 addition & 1 deletion src/internal/storage/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fs::Permissions;



fn init(root_dir: PathBuf, storage_dir: PathBuf, mode: u32, gid: u32) -> Result<(), std::io::Error> { //
pub fn init(root_dir: &PathBuf, storage_dir: &PathBuf, mode: &u32, gid: &u32) -> Result<(), std::io::Error> { //
// get storage directory as an absolute path
let storage_dir_abs: PathBuf = match storage_dir.canonicalize() {
Ok(storage_dir_abs) => {
Expand Down
22 changes: 16 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
use std::path::PathBuf;
use std::env;
use clap::{arg, Command, ArgAction, Arg};
use std::io;

mod internal;
use crate::internal::storage::init;
use crate::internal::config::config;
use crate::internal::git::repo;
// use git_discover;

mod cmd;
use crate::cmd::init_cmd;

fn main() {
fn main() -> io::Result<()> {
let intro = Command::new("🌀 Devious")
.version("0.0.1")
.author("Andriy Massimilla, Jenna Johnson")
.about("version large files under Git")
.arg_required_else_help(false)
.get_matches();






let current = env::current_dir().unwrap().display().to_string();
println!("{current}");
let nearest_repo = repo::get_nearest_repo_dir(PathBuf::from(r"src")).unwrap().display().to_string();
let nearest_repo = repo::get_nearest_repo_dir(&PathBuf::from(r"src")).unwrap().display().to_string();
println!("NEAREST PATH: {nearest_repo}");



let dir = PathBuf::from("/cluster-data/user-homes/jenna/Projects/devious/src");
let config = config::Config{storage_dir: dir.clone()};

Expand Down

0 comments on commit ba90c2d

Please sign in to comment.