imag-ref: implement ImagApplication

Signed-off-by: Leon Schuermann <leon@is.currently.online>
This commit is contained in:
Leon Schuermann 2019-09-14 18:46:07 +02:00 committed by Matthias Beyer
parent 186b03deea
commit fec52bdbc5
3 changed files with 90 additions and 23 deletions

View file

@ -35,3 +35,10 @@ version = "2.33.0"
default-features = false default-features = false
features = ["color", "suggestions", "wrap_help"] features = ["color", "suggestions", "wrap_help"]
[lib]
name = "libimagrefcmd"
path = "src/lib.rs"
[[bin]]
name = "imag-ref"
path = "src/bin.rs"

View file

@ -0,0 +1,39 @@
//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015-2019 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
//
#![forbid(unsafe_code)]
#![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,
)]
#[macro_use] extern crate libimagrt;
simple_imag_application_binary!(libimagrefcmd, ImagRef);

View file

@ -39,23 +39,24 @@ extern crate clap;
#[macro_use] extern crate failure; #[macro_use] extern crate failure;
extern crate libimagstore; extern crate libimagstore;
#[macro_use] extern crate libimagrt; extern crate libimagrt;
extern crate libimagentryref; extern crate libimagentryref;
extern crate libimagerror; extern crate libimagerror;
extern crate libimaginteraction; extern crate libimaginteraction;
extern crate libimagutil; extern crate libimagutil;
mod ui; mod ui;
use crate::ui::build_ui;
use std::process::exit; use std::process::exit;
use std::io::Write; use std::io::Write;
use failure::Error; use failure::Error;
use failure::Fallible as Result;
use clap::App;
use libimagerror::trace::MapErrTrace; use libimagerror::trace::MapErrTrace;
use libimagerror::exit::ExitUnwrap; use libimagerror::exit::ExitUnwrap;
use libimagrt::setup::generate_runtime_setup; use libimagrt::application::ImagApplication;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagentryref::reference::Ref; use libimagentryref::reference::Ref;
use libimagentryref::reference::MutRef; use libimagentryref::reference::MutRef;
@ -63,27 +64,47 @@ use libimagentryref::reference::RefFassade;
use libimagentryref::hasher::default::DefaultHasher; use libimagentryref::hasher::default::DefaultHasher;
use libimagentryref::util::get_ref_config; use libimagentryref::util::get_ref_config;
fn main() { /// Marker enum for implementing ImagApplication on
let version = make_imag_version!(); ///
let rt = generate_runtime_setup("imag-ref", /// This is used by binaries crates to execute business logic
&version, /// or to build a CLI completion.
"Reference files outside of the store", pub enum ImagRef {}
build_ui); impl ImagApplication for ImagRef {
if let Some(name) = rt.cli().subcommand_name() { fn run(rt: Runtime) -> Result<()> {
debug!("Call: {}", name); if let Some(name) = rt.cli().subcommand_name() {
match name { debug!("Call: {}", name);
"deref" => deref(&rt), match name {
"create" => create(&rt), "deref" => deref(&rt),
"remove" => remove(&rt), "create" => create(&rt),
"list-dead" => list_dead(&rt), "remove" => remove(&rt),
other => { "list-dead" => list_dead(&rt),
debug!("Unknown command"); other => {
let _ = rt.handle_unknown_subcommand("imag-ref", other, rt.cli()) debug!("Unknown command");
.map_err_trace_exit_unwrap() let _ = rt.handle_unknown_subcommand("imag-ref", other, rt.cli())
.code() .map_err_trace_exit_unwrap()
.map(::std::process::exit); .code()
}, .map(::std::process::exit);
},
}
}; };
Ok(())
}
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
ui::build_ui(app)
}
fn name() -> &'static str {
env!("CARGO_PKG_NAME")
}
fn description() -> &'static str {
"Reference files outside of the store"
}
fn version() -> &'static str {
env!("CARGO_PKG_VERSION")
} }
} }