imag/bin/core/imag-store/src/lib.rs

127 lines
3.3 KiB
Rust
Raw Normal View History

//
// 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
//
2018-09-27 06:13:58 +00:00
#![forbid(unsafe_code)]
2016-04-21 11:27:05 +00:00
#![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,
)]
2016-01-23 14:38:14 +00:00
extern crate clap;
#[macro_use] extern crate log;
extern crate toml;
extern crate resiter;
2017-09-03 20:00:34 +00:00
#[cfg(test)] extern crate toml_query;
#[macro_use] extern crate failure;
2016-01-23 14:38:14 +00:00
extern crate libimagrt;
2016-01-23 14:38:14 +00:00
extern crate libimagstore;
2017-09-03 18:41:43 +00:00
extern crate libimagerror;
2016-01-23 14:38:14 +00:00
2017-09-03 20:00:34 +00:00
#[cfg(test)]
#[macro_use]
extern crate libimagutil;
2017-09-03 20:00:34 +00:00
#[cfg(not(test))]
extern crate libimagutil;
use libimagrt::application::ImagApplication;
use libimagrt::runtime::Runtime;
use failure::Fallible as Result;
use failure::err_msg;
2016-01-23 15:29:04 +00:00
mod create;
2016-05-27 09:26:22 +00:00
mod delete;
mod get;
mod retrieve;
2016-05-27 09:26:22 +00:00
mod ui;
2016-01-23 15:29:04 +00:00
mod update;
2016-07-16 22:45:51 +00:00
mod verify;
mod util;
2016-01-23 15:01:17 +00:00
2017-06-18 18:00:47 +00:00
use std::ops::Deref;
use clap::App;
use crate::create::create;
use crate::delete::delete;
use crate::get::get;
use crate::retrieve::retrieve;
use crate::update::update;
use crate::verify::verify;
2016-01-23 15:01:17 +00:00
/// Marker enum for implementing ImagApplication on
///
/// This is used by binaries crates to execute business logic
/// or to build a CLI completion.
pub enum ImagStore {}
impl ImagApplication for ImagStore {
fn run(rt: Runtime) -> Result<()> {
if let Some(command) = rt.cli().subcommand_name() {
debug!("Call: {}", command);
match command.deref() {
"create" => create(&rt),
"delete" => delete(&rt),
"get" => get(&rt),
"retrieve" => retrieve(&rt),
"update" => update(&rt),
"verify" => verify(&rt),
other => {
debug!("Unknown command");
if rt.handle_unknown_subcommand("imag-store", other, rt.cli())?.success() {
Ok(())
} else {
Err(format_err!("Subcommand failed"))
}
},
}
} else {
Err(err_msg("No command"))
}
}
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
ui::build_ui(app)
2017-06-18 18:00:47 +00:00
}
2016-01-23 15:29:04 +00:00
fn name() -> &'static str {
env!("CARGO_PKG_NAME")
}
fn description() -> &'static str {
"Direct interface to the store. Use with great care!"
}
fn version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
}