diff options
author | Leon Schuermann <leon@is.currently.online> | 2019-09-14 18:44:01 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-10-26 14:41:31 +0200 |
commit | 208d6e62e60f4d80658629c2c13280c4bdab448c (patch) | |
tree | 881b54a949083d97377d1b9dfa3b1a944ad597c9 | |
parent | 0739fed6662154f484eb615c92373d37ce2977fe (diff) |
imag-init: implement ImagApplication
Signed-off-by: Leon Schuermann <leon@is.currently.online>
-rw-r--r-- | bin/core/imag-init/Cargo.toml | 9 | ||||
-rw-r--r-- | bin/core/imag-init/src/bin.rs | 46 | ||||
-rw-r--r-- | bin/core/imag-init/src/lib.rs (renamed from bin/core/imag-init/src/main.rs) | 35 |
3 files changed, 88 insertions, 2 deletions
diff --git a/bin/core/imag-init/Cargo.toml b/bin/core/imag-init/Cargo.toml index 9701794c..cf68ef8c 100644 --- a/bin/core/imag-init/Cargo.toml +++ b/bin/core/imag-init/Cargo.toml @@ -20,6 +20,8 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" } maintenance = { status = "actively-developed" } [dependencies] +failure = "0.1.5" + libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } @@ -31,3 +33,10 @@ features = ["color", "suggestions", "wrap_help"] [dev-dependencies] toml = "0.5.1" +[lib] +name = "libimaginitcmd" +path = "src/lib.rs" + +[[bin]] +name = "imag-init" +path = "src/bin.rs" diff --git a/bin/core/imag-init/src/bin.rs b/bin/core/imag-init/src/bin.rs new file mode 100644 index 00000000..aea6ebc3 --- /dev/null +++ b/bin/core/imag-init/src/bin.rs @@ -0,0 +1,46 @@ +// +// 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, +)] + +extern crate failure; +use failure::Fallible as Result; + +extern crate libimaginitcmd; + + +fn main() -> Result<()> { + libimaginitcmd::imag_init(); + Ok(()) +} diff --git a/bin/core/imag-init/src/main.rs b/bin/core/imag-init/src/lib.rs index 5935a812..e2033e3d 100644 --- a/bin/core/imag-init/src/main.rs +++ b/bin/core/imag-init/src/lib.rs @@ -35,7 +35,7 @@ )] extern crate clap; - +extern crate failure; #[cfg(test)] extern crate toml; @@ -53,6 +53,10 @@ use std::process::Command; use libimagerror::exit::ExitUnwrap; use libimagerror::io::ToExitCode; use libimagrt::runtime::Runtime; +use libimagrt::application::ImagApplication; + +use failure::Fallible as Result; +use clap::App; const CONFIGURATION_STR : &str = include_str!("../imagrc.toml"); @@ -69,7 +73,34 @@ const GITIGNORE_STR : &str = r#" imagrc.toml "#; -fn main() { +/// Marker enum for implementing ImagApplication on +/// +/// This is used by binaries crates to execute business logic +/// or to build a CLI completion. +pub enum ImagInit {} +impl ImagApplication for ImagInit { + fn run(_rt: Runtime) -> Result<()> { + panic!("imag-init needs to be run as a seperate binary, or we'll need to figure something out here!"); + } + + 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 { + "Intialize the imag store" + } + + fn version() -> &'static str { + env!("CARGO_PKG_VERSION") + } +} + +pub fn imag_init() { let version = make_imag_version!(); let app = ui::build_ui(Runtime::get_default_cli_builder( "imag-init", |