feat(add): start add logic and ignorer
This commit is contained in:
46
src/subcommands/add.rs
Normal file
46
src/subcommands/add.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
||||
|
||||
use crate::commands;
|
||||
use crate::commands::add::AddArgs;
|
||||
use crate::config::config::Config;
|
||||
|
||||
pub fn create() -> Command {
|
||||
Command::new("add")
|
||||
.arg(
|
||||
Arg::new("files")
|
||||
.required_unless_present("all")
|
||||
.conflicts_with("all")
|
||||
.num_args(1..)
|
||||
.value_name("FILE")
|
||||
.help("Files to add"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("force")
|
||||
.short('f')
|
||||
.long("force")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Allow adding otherwise ignored files."),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("all")
|
||||
.short('A')
|
||||
.long("all")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("This adds, modifies, and removes index entries to match the working tree"),
|
||||
)
|
||||
.about("Add changes to the index")
|
||||
}
|
||||
|
||||
pub fn handler(args: &ArgMatches) {
|
||||
commands::add::exec(
|
||||
AddArgs {
|
||||
files: match args.get_many::<String>("files") {
|
||||
None => vec![],
|
||||
Some(vals) => vals.map(|s| s.to_string()).collect(),
|
||||
},
|
||||
force: *args.get_one::<bool>("force").unwrap(),
|
||||
all: *args.get_one::<bool>("all").unwrap(),
|
||||
},
|
||||
Config::new(),
|
||||
);
|
||||
}
|
||||
@@ -16,5 +16,5 @@ pub fn create() -> Command {
|
||||
|
||||
pub fn handler(args: &ArgMatches) {
|
||||
let exec_dir = args.get_one::<String>("directory");
|
||||
commands::init::exec(commands::init::InitArgs {}, Config::new(exec_dir));
|
||||
commands::init::exec(commands::init::InitArgs {}, Config::from(exec_dir));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user