Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sdttttt/gcr
Browse files Browse the repository at this point in the history
  • Loading branch information
sdttttt committed Sep 30, 2020
2 parents 6b4aeda + 3034475 commit 8d57dcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
25 changes: 14 additions & 11 deletions src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,24 @@ impl Arguments {
.version(VERSION)
.author(AUTHOR)
.about(DESCRIPTION)
.args(&[Self::push_arg(PUSH_COMMAND), Self::add_arg(ADD_COMMAND)])
.args(&[Self::add_arg(ADD_PARAMS)])
// .args(&[Self::push_arg(PUSH_PARAMS), Self::add_arg(ADD_PARAMS)])
}

fn push_arg(command_name: &str) -> Arg {
Arg::with_name(command_name)
fn push_arg(params_name: &str) -> Arg {
Arg::with_name(params_name)
.short(PUSH_COMMAND_SHORT)
.long(command_name)
.long(PUSH_COMMAND)
.multiple(true)
.required(false)
.help(PUSH_COMMAND_HELP)
.takes_value(true)
}

fn add_arg(command_name: &str) -> Arg {
Arg::with_name(command_name)
fn add_arg(params_name: &str) -> Arg {
Arg::with_name(params_name)
.short(ADD_COMMAND_SHORT)
.long(command_name)
.long(ADD_COMMAND)
.multiple(true)
.required(false)
.help(ADD_COMMAND_HELP)
Expand All @@ -58,8 +59,8 @@ impl Arguments {

fn resolve_command(matches: ArgMatches) -> Result<Self, Error> {
let arg: Self;
if matches.is_present(ADD_COMMAND) {
if let Some(files) = matches.values_of(ADD_COMMAND) {
if matches.is_present(ADD_PARAMS) {
if let Some(files) = matches.values_of(ADD_PARAMS) {
let files_vec: Vec<String> = vec_str_to_string(files.collect());
if files_vec.len() == 1 && files_vec[0] == "." {
arg = Self::new(Mode::AddAll, vec![]);
Expand All @@ -69,8 +70,8 @@ impl Arguments {
} else {
return Err(Error::from_str(ADD_COMMAND_NO_FILE));
}
} else if matches.is_present(PUSH_COMMAND) {
if let Some(files) = matches.values_of(PUSH_COMMAND) {
} else if matches.is_present(PUSH_PARAMS) {
if let Some(files) = matches.values_of(PUSH_PARAMS) {
let files_vec: Vec<String> = vec_str_to_string(files.collect());
if files_vec.len() == 1 && files_vec[0] == "." {
arg = Self::new(Mode::Auto, vec![]);
Expand Down Expand Up @@ -117,6 +118,7 @@ mod tests {
}

#[test]
#[ignore]
fn push_mode() {
let args = quick_command_run(vec!["grc", "--push", "ytsur"]);
match args.command_mode() {
Expand All @@ -126,6 +128,7 @@ mod tests {
}

#[test]
#[ignore]
fn auto_mode() {
let args = quick_command_run(vec!["grc", "--push", "."]);
match args.command_mode() {
Expand Down
5 changes: 3 additions & 2 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ pub enum Mode {
}

pub const ADD_COMMAND: &str = "add";
pub const ADD_PARAMS: &str = "add_file_name";
pub const ADD_COMMAND_SHORT: &str = "a";
// TODO: Fill in the `add` command help
pub const ADD_COMMAND_HELP: &str = "...";
pub const ADD_COMMAND_HELP: &str = "Help you add files before commit. If the parameter is `.`, Then GRC will help you add everything.";
pub const ADD_COMMAND_NO_FILE: &str = "The add command requires parameters.";

pub const PUSH_COMMAND: &str = "push";
pub const PUSH_PARAMS: &str = "push_file_name";
pub const PUSH_COMMAND_SHORT: &str = "p";
// TODO: Fill in the `push` command help
pub const PUSH_COMMAND_HELP: &str = "...";
Expand Down

0 comments on commit 8d57dcf

Please sign in to comment.