Merge pull request #1469 from matthiasbeyer/imag-diary/remove-edit-command

Remove the edit command
This commit is contained in:
Matthias Beyer 2018-04-30 17:33:35 +02:00 committed by GitHub
commit ebc2e49c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 82 deletions

View File

@ -1,66 +0,0 @@
//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015-2018 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 std::process::exit;
use chrono::naive::NaiveDateTime;
use libimagdiary::diary::Diary;
use libimagdiary::diaryid::DiaryId;
use libimagdiary::error::DiaryErrorKind as DEK;
use libimagdiary::error::DiaryError as DE;
use libimagdiary::error::ResultExt;
use libimagentryedit::edit::Edit;
use libimagrt::runtime::Runtime;
use libimagerror::trace::MapErrTrace;
use libimagtimeui::datetime::DateTime;
use libimagtimeui::parse::Parse;
use libimagutil::warn_exit::warn_exit;
use util::get_diary_name;
pub fn edit(rt: &Runtime) {
let diaryname = get_diary_name(rt).unwrap_or_else(|| warn_exit("No diary name", 1));
rt.cli()
.subcommand_matches("edit")
.unwrap()
.value_of("datetime")
.and_then(DateTime::parse)
.map(|dt| dt.into())
.map(|dt: NaiveDateTime| DiaryId::from_datetime(diaryname.clone(), dt))
.or_else(|| {
rt.store()
.get_youngest_entry_id(&diaryname)
.map(|o| o.map_err_trace_exit_unwrap(1))
})
.ok_or_else(|| {
error!("No entries in diary. Aborting");
exit(1)
})
.and_then(|id| rt.store().get(id))
.map(|opte| match opte {
Some(mut e) => e.edit_content(rt).chain_err(|| DEK::IOError),
None => Err(DE::from_kind(DEK::EntryNotInDiary)),
})
.map_err_trace()
.ok();
}

View File

@ -59,7 +59,6 @@ use itertools::Itertools;
mod create; mod create;
mod delete; mod delete;
mod edit;
mod list; mod list;
mod ui; mod ui;
mod util; mod util;
@ -67,7 +66,6 @@ mod view;
use create::create; use create::create;
use delete::delete; use delete::delete;
use edit::edit;
use list::list; use list::list;
use view::view; use view::view;
@ -86,7 +84,6 @@ fn main() {
"diaries" => diaries(&rt), "diaries" => diaries(&rt),
"create" => create(&rt), "create" => create(&rt),
"delete" => delete(&rt), "delete" => delete(&rt),
"edit" => edit(&rt),
"list" => list(&rt), "list" => list(&rt),
"view" => view(&rt), "view" => view(&rt),
other => { other => {

View File

@ -77,19 +77,6 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.requires("timed")) .requires("timed"))
) )
.subcommand(SubCommand::with_name("edit")
.about("Edit a diary entry")
.version("0.1")
.arg(Arg::with_name("datetime")
.long("datetime")
.short("d")
.takes_value(true)
.required(false)
.help("Specify the date and time which entry should be edited. If none is
specified, the last entry is edited. If the diary entry does not exist for
this time, this fails. Format: YYYY-MM-DDT[HH[:mm[:ss]]]"))
)
.subcommand(SubCommand::with_name("list") .subcommand(SubCommand::with_name("list")
.about("List diary entries") .about("List diary entries")
.version("0.1")) .version("0.1"))