Merge pull request #1209 from matthiasbeyer/imag-edit/init
Add imag-edit command
This commit is contained in:
commit
7fdc71230e
8 changed files with 184 additions and 1 deletions
|
@ -3,6 +3,7 @@ members = [
|
||||||
"bin/core/imag",
|
"bin/core/imag",
|
||||||
"bin/core/imag-annotate",
|
"bin/core/imag-annotate",
|
||||||
"bin/core/imag-diagnostics",
|
"bin/core/imag-diagnostics",
|
||||||
|
"bin/core/imag-edit",
|
||||||
"bin/core/imag-gps",
|
"bin/core/imag-gps",
|
||||||
"bin/core/imag-grep",
|
"bin/core/imag-grep",
|
||||||
"bin/core/imag-init",
|
"bin/core/imag-init",
|
||||||
|
|
46
bin/core/imag-edit/Cargo.toml
Normal file
46
bin/core/imag-edit/Cargo.toml
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
[package]
|
||||||
|
name = "imag-edit"
|
||||||
|
version = "0.6.0"
|
||||||
|
authors = ["Matthias Beyer <mail@beyermatthias.de>"]
|
||||||
|
|
||||||
|
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"]
|
||||||
|
|
1
bin/core/imag-edit/README.md
Symbolic link
1
bin/core/imag-edit/README.md
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../../doc/src/04020-module-edit.md
|
87
bin/core/imag-edit/src/main.rs
Normal file
87
bin/core/imag-edit/src/main.rs
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> 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");
|
||||||
|
}
|
||||||
|
|
40
bin/core/imag-edit/src/ui.rs
Normal file
40
bin/core/imag-edit/src/ui.rs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> 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"))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
7
doc/src/04020-module-edit.md
Normal file
7
doc/src/04020-module-edit.md
Normal file
|
@ -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).
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
## libimagentryedit
|
## libimagentryedit {#sec:lib:entryedit}
|
||||||
|
|
||||||
Provides edit (as in spawning an `$EDITOR`) functionality for entries.
|
Provides edit (as in spawning an `$EDITOR`) functionality for entries.
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ This section contains the changelog from the last release to the next release.
|
||||||
the function way better.
|
the function way better.
|
||||||
* `libimagentryutil` was introduced, a library for helpers for
|
* `libimagentryutil` was introduced, a library for helpers for
|
||||||
`libimagstore::store::Entry` handling and writing extension-writing.
|
`libimagstore::store::Entry` handling and writing extension-writing.
|
||||||
|
* `imag-edit` was introduced
|
||||||
* Minor changes
|
* Minor changes
|
||||||
* Internals were refactored from `match`ing all the things into function
|
* Internals were refactored from `match`ing all the things into function
|
||||||
chaining
|
chaining
|
||||||
|
|
Loading…
Reference in a new issue