diff --git a/Cargo.toml b/Cargo.toml index a80bbfb2..7d42d5b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "bin/core/imag", "bin/core/imag-annotate", "bin/core/imag-category", + "bin/core/imag-create", "bin/core/imag-diagnostics", "bin/core/imag-edit", "bin/core/imag-git", diff --git a/bin/core/imag-create/Cargo.toml b/bin/core/imag-create/Cargo.toml new file mode 100644 index 00000000..4aac3d4f --- /dev/null +++ b/bin/core/imag-create/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "imag-create" +version = "0.10.0" +authors = ["Matthias Beyer "] +edition = "2018" + +description = "Part of the imag core distribution: imag-diagnostics command" + +keywords = ["imag", "PIM", "personal", "information", "management"] +readme = "../../../README.md" +license = "LGPL-2.1" + +documentation = "https://imag-pim.org/doc/" +repository = "https://github.com/matthiasbeyer/imag" +homepage = "http://imag-pim.org" + +[dependencies] +log = "0.4" +failure = "0.1" + +libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } +libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } +libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } + +[dependencies.clap] +version = "2.33.0" +default-features = false +features = ["suggestions", "color", "wrap_help"] + diff --git a/bin/core/imag-create/src/main.rs b/bin/core/imag-create/src/main.rs new file mode 100644 index 00000000..7083f074 --- /dev/null +++ b/bin/core/imag-create/src/main.rs @@ -0,0 +1,76 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +//#![deny( +// non_camel_case_types, +// non_snake_case, +// path_statements, +// trivial_numeric_casts, +// unstable_features, +// unused_allocation, +// unused_import_braces, +// unused_imports, +// unused_must_use, +// unused_mut, +// unused_qualifications, +// while_true, +//)] + +extern crate clap; +extern crate failure; +#[macro_use] extern crate log; + +extern crate libimagerror; +#[macro_use] extern crate libimagrt; +extern crate libimagstore; + +use failure::Fallible as Result; + +use libimagerror::trace::MapErrTrace; +use libimagrt::setup::generate_runtime_setup; +use libimagstore::iter::create::StoreIdCreateIteratorExtension; +use libimagstore::iter::retrieve::StoreIdRetrieveIteratorExtension; + +mod ui; + +fn main() { + let version = make_imag_version!(); + let rt = generate_runtime_setup("imag-create", + &version, + "Plumbing tool creating entries", + ui::build_ui); + + let force = rt.cli().is_present("force"); + + let ids = rt.ids::() + .map_err_trace_exit_unwrap() + .unwrap_or_else(|| { + error!("No ids supplied"); + ::std::process::exit(1); + }) + .into_iter() + .map(Ok); + + if force { + ids.into_retrieve_iter(rt.store()).collect::>>() + } else { + ids.into_create_iter(rt.store()).collect::>>() + }.map_err_trace_exit_unwrap(); +} + diff --git a/bin/core/imag-create/src/ui.rs b/bin/core/imag-create/src/ui.rs new file mode 100644 index 00000000..83cef6dd --- /dev/null +++ b/bin/core/imag-create/src/ui.rs @@ -0,0 +1,58 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +use std::path::PathBuf; + +use clap::{Arg, ArgMatches, App}; +use failure::Fallible as Result; + +use libimagstore::storeid::StoreId; +use libimagstore::storeid::IntoStoreId; +use libimagrt::runtime::IdPathProvider; + +pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { + app.arg(Arg::with_name("id") + .index(1) + .takes_value(true) + .required(false) + .multiple(true) + .help("Entries to create")) + .arg(Arg::with_name("force") + .long("force") + .short("F") + .takes_value(false) + .required(false) + .multiple(false) + .help("Do not fail if entry already exists")) +} + +pub struct PathProvider; +impl IdPathProvider for PathProvider { + fn get_ids(matches: &ArgMatches) -> Result>> { + matches.values_of("id") + .map(|v| v + .map(PathBuf::from) + .map(|pb| pb.into_storeid()) + .collect::>>() + ) + .transpose() + } +} + + diff --git a/scripts/release.sh b/scripts/release.sh index 25f5f310..643eae1b 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -66,6 +66,7 @@ CRATES=( ./bin/core/imag-git ./bin/core/imag-category ./bin/core/imag-header + ./bin/core/imag-create ./bin/core/imag )