diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-02-06 11:54:36 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-02-09 13:48:14 +0100 |
commit | 04a5bb913844d9102f1ab172f01e1f0f38d5dcad (patch) | |
tree | 23c82486bac66477f49106ce5ed3c748cb3c9404 /imag-store | |
parent | a59ce2003ceaae910a59f0ae515688260e36d0fe (diff) |
Allow --id / -i as path specification, for consistency
Diffstat (limited to 'imag-store')
-rw-r--r-- | imag-store/src/create.rs | 12 | ||||
-rw-r--r-- | imag-store/src/ui.rs | 8 | ||||
-rw-r--r-- | imag-store/tests/001-create_test.sh | 18 |
3 files changed, 36 insertions, 2 deletions
diff --git a/imag-store/src/create.rs b/imag-store/src/create.rs index 086b4698..03164581 100644 --- a/imag-store/src/create.rs +++ b/imag-store/src/create.rs @@ -4,6 +4,9 @@ use std::fs::OpenOptions; use std::result::Result as RResult; use std::io::Read; use std::ops::DerefMut; +use std::io::Write; +use std::io::stderr; +use std::process::exit; use clap::ArgMatches; @@ -25,7 +28,14 @@ pub fn create(rt: &Runtime) { debug!("Found 'create' subcommand..."); // unwrap is safe as value is required - let path = build_entry_path(rt, scmd.value_of("path").unwrap()); + let path = scmd.value_of("path").or_else(|| scmd.value_of("id")); + if path.is_none() { + warn!("No ID / Path provided. Exiting now"); + write!(stderr(), "No ID / Path provided. Exiting now"); + exit(1); + } + + let path = build_entry_path(rt, path.unwrap()); debug!("path = {:?}", path); if scmd.subcommand_matches("entry").is_some() { diff --git a/imag-store/src/ui.rs b/imag-store/src/ui.rs index ae55d8fb..da8886f7 100644 --- a/imag-store/src/ui.rs +++ b/imag-store/src/ui.rs @@ -8,8 +8,14 @@ pub fn build_ui<'a>(app: App<'a, 'a, 'a, 'a, 'a, 'a>) -> App<'a, 'a, 'a, 'a, 'a, .long("path") .short("p") .takes_value(true) - .required(true) + .required(false) .help("Create at this store path")) + .arg(Arg::with_name("id") + .long("id") + .short("i") + .takes_value(true) + .required(false) + .help("Same as --path, for consistency")) .arg(Arg::with_name("from-raw") .long("from-raw") .takes_value(true) diff --git a/imag-store/tests/001-create_test.sh b/imag-store/tests/001-create_test.sh index 2bcec63a..65870769 100644 --- a/imag-store/tests/001-create_test.sh +++ b/imag-store/tests/001-create_test.sh @@ -10,6 +10,22 @@ test_call() { fi } +test_call_id() { + imag-store create -i /test-call~0.1.0 + if [[ ! $? -eq 0 ]]; then + err "Return value should be zero, was non-zero" + return 1; + fi +} + +test_call_no_id() { + imag-store create + if [[ ! $? -eq 1 ]]; then + err "Return value should be zero, was non-zero" + return 1; + fi +} + test_mkstore() { imag-store create -p /test-mkstore~0.1.0 || { err "Calling imag failed"; return 1; } if [[ -d ${STORE} ]]; then @@ -147,6 +163,8 @@ EOS invoke_tests \ test_call \ + test_call_id \ + test_call_no_id \ test_mkstore \ test_std_header \ test_std_header_plus_custom \ |