Rewrite create() to use positional arg
This commit is contained in:
parent
e6d96c9f83
commit
a71732be49
2 changed files with 27 additions and 52 deletions
|
@ -23,9 +23,6 @@ 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;
|
||||
use toml::Value;
|
||||
|
@ -44,24 +41,15 @@ use util::build_toml_header;
|
|||
type Result<T> = RResult<T, StoreError>;
|
||||
|
||||
pub fn create(rt: &Runtime) {
|
||||
rt.cli()
|
||||
.subcommand_matches("create")
|
||||
.map(|scmd| {
|
||||
let scmd = rt.cli().subcommand_matches("create").unwrap();
|
||||
debug!("Found 'create' subcommand...");
|
||||
|
||||
// unwrap is safe as value is required
|
||||
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").ok();
|
||||
exit(1);
|
||||
}
|
||||
let path = scmd.value_of("path").unwrap();
|
||||
let path = PathBuf::from(path);
|
||||
let store = Some(rt.store().path().clone());
|
||||
let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1));
|
||||
|
||||
let store_path = rt.store().path().clone();
|
||||
let path = match StoreId::new(Some(store_path), PathBuf::from(path.unwrap())) {
|
||||
Err(e) => trace_error_exit(&e, 1),
|
||||
Ok(o) => o,
|
||||
};
|
||||
debug!("path = {:?}", path);
|
||||
|
||||
if scmd.subcommand_matches("entry").is_some() {
|
||||
|
@ -81,7 +69,6 @@ pub fn create(rt: &Runtime) {
|
|||
error!("Error building Entry");
|
||||
trace_error_exit(&e, 1);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> {
|
||||
|
|
|
@ -24,29 +24,17 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
|||
.about("Create an entry from the store")
|
||||
.version("0.1")
|
||||
.arg(Arg::with_name("path")
|
||||
.long("path")
|
||||
.short("p")
|
||||
.index(1)
|
||||
.takes_value(true)
|
||||
.required(false)
|
||||
.required(true)
|
||||
.help("Create at this store path")
|
||||
.value_name("PATH"))
|
||||
.arg(Arg::with_name("id")
|
||||
.long("id")
|
||||
.short("i")
|
||||
.takes_value(true)
|
||||
.required(false)
|
||||
.help("Same as --path, for consistency")
|
||||
.value_name("PATH"))
|
||||
.arg(Arg::with_name("from-raw")
|
||||
.long("from-raw")
|
||||
.takes_value(true)
|
||||
.help("Create a new entry by reading this file ('-' for stdin)")
|
||||
.value_name("FILE"))
|
||||
|
||||
.group(ArgGroup::with_name("create-destination-group")
|
||||
.args(&["path", "id"])
|
||||
.required(true))
|
||||
|
||||
.subcommand(SubCommand::with_name("entry")
|
||||
.about("Create an entry via commandline")
|
||||
.version("0.1")
|
||||
|
|
Loading…
Reference in a new issue