diff --git a/Cargo.toml b/Cargo.toml index c800dc4c..2d0dcb6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "bin/core/imag", "bin/core/imag-annotate", "bin/core/imag-diagnostics", + "bin/core/imag-edit", "bin/core/imag-gps", "bin/core/imag-grep", "bin/core/imag-init", diff --git a/bin/core/imag-edit/Cargo.toml b/bin/core/imag-edit/Cargo.toml new file mode 100644 index 00000000..b053519f --- /dev/null +++ b/bin/core/imag-edit/Cargo.toml @@ -0,0 +1,46 @@ +[package] +name = "imag-edit" +version = "0.6.0" +authors = ["Matthias Beyer "] + +description = "Part of the imag core distribution: imag-edit command" + +keywords = ["imag", "PIM", "personal", "information", "management"] +readme = "../../../README.md" +license = "LGPL-2.1" + +documentation = "https://matthiasbeyer.github.io/imag/imag_documentation/index.html" +repository = "https://github.com/matthiasbeyer/imag" +homepage = "http://imag-pim.org" + +[badges] +travis-ci = { repository = "matthiasbeyer/imag" } +is-it-maintained-issue-resolution = { repository = "matthiasbeyer/imag" } +is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" } +maintenance = { status = "actively-developed" } + +[dependencies] +clap = ">=2.17" +log = "0.3" +version = "2.0.1" +toml = "0.4" +toml-query = "0.4" + +libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } +libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" } +libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" } +libimagutil = { version = "0.6.0", path = "../../../lib/etc/libimagutil" } +libimagentryedit = { version = "0.6.0", path = "../../../lib/entry/libimagentryedit" } + +[dev-dependencies.libimagutil] +version = "0.6.0" +path = "../../../lib/etc/libimagutil" +default-features = false +features = ["testing"] + +[dev-dependencies.libimagrt] +version = "0.6.0" +path = "../../../lib/core/libimagrt" +default-features = false +features = ["testing"] + diff --git a/bin/core/imag-edit/README.md b/bin/core/imag-edit/README.md new file mode 120000 index 00000000..8c83bd3f --- /dev/null +++ b/bin/core/imag-edit/README.md @@ -0,0 +1 @@ +../../../doc/src/04020-module-edit.md \ No newline at end of file diff --git a/bin/core/imag-edit/src/main.rs b/bin/core/imag-edit/src/main.rs new file mode 100644 index 00000000..e6ae04ff --- /dev/null +++ b/bin/core/imag-edit/src/main.rs @@ -0,0 +1,87 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 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; +#[macro_use] extern crate log; +#[macro_use] extern crate version; + +extern crate libimagentryedit; +extern crate libimagerror; +extern crate libimagrt; +extern crate libimagstore; +extern crate libimagutil; + +use std::path::PathBuf; + +use libimagentryedit::edit::*; +use libimagentryedit::error::EditError as EE; +use libimagerror::trace::MapErrTrace; +use libimagrt::setup::generate_runtime_setup; +use libimagstore::storeid::IntoStoreId; + +mod ui; + +fn main() { + let rt = generate_runtime_setup("imag-edit", + &version!()[..], + "Edit store entries with $EDITOR", + ui::build_ui); + + let mut entry = { + let path = rt.cli() + .value_of("entry") + .unwrap(); // safe by clap + + let sid = PathBuf::from(path).into_storeid().map_err_trace_exit_unwrap(1); + + rt.store() + .get(sid) + .map_err_trace_exit_unwrap(1) + .ok_or(EE::from(format!("Entry {} does not exist", path))) + .map_err_trace_exit_unwrap(1) + }; + + if rt.cli().is_present("edit-header") { + // TODO: support editing of header + warn!("Editing header is not yet supported by imag-edit"); + ::std::process::exit(1); + } + + let _ = entry + .edit_content(&rt) + .map_err_trace_exit_unwrap(1); + + info!("Ok"); +} + diff --git a/bin/core/imag-edit/src/ui.rs b/bin/core/imag-edit/src/ui.rs new file mode 100644 index 00000000..a7587c39 --- /dev/null +++ b/bin/core/imag-edit/src/ui.rs @@ -0,0 +1,40 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 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 clap::{Arg, App}; + +pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { + app + .arg(Arg::with_name("entry") + .index(1) + .takes_value(true) + .required(true) + .multiple(true) + .help("The entry/entries to edit") + .value_name("ENTRY")) + .arg(Arg::with_name("edit-header") + .long("header") + .short("H") + .takes_value(false) + .required(false) + .multiple(false) + .help("Also edit the header")) + +} + diff --git a/doc/src/04020-module-edit.md b/doc/src/04020-module-edit.md new file mode 100644 index 00000000..75761d54 --- /dev/null +++ b/doc/src/04020-module-edit.md @@ -0,0 +1,7 @@ +## Edit {#sec:modules:edit} + +The `imag-edit` command is for simply editing store entries with the +`$EDITOR`. + +It is based on libimagentryedit (@sec:lib:entryedit). + diff --git a/doc/src/05100-lib-entryedit.md b/doc/src/05100-lib-entryedit.md index 42374e48..285b5e5e 100644 --- a/doc/src/05100-lib-entryedit.md +++ b/doc/src/05100-lib-entryedit.md @@ -1,4 +1,4 @@ -## libimagentryedit +## libimagentryedit {#sec:lib:entryedit} Provides edit (as in spawning an `$EDITOR`) functionality for entries. diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md index eeb73392..022d98d4 100644 --- a/doc/src/09020-changelog.md +++ b/doc/src/09020-changelog.md @@ -31,6 +31,7 @@ This section contains the changelog from the last release to the next release. the function way better. * `libimagentryutil` was introduced, a library for helpers for `libimagstore::store::Entry` handling and writing extension-writing. + * `imag-edit` was introduced * Minor changes * Internals were refactored from `match`ing all the things into function chaining