2017-06-07 15:51:43 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
|
2016-11-01 19:06:38 +00:00
|
|
|
extern crate clap;
|
|
|
|
extern crate libimagrt;
|
2016-11-02 18:43:27 +00:00
|
|
|
extern crate libimagentrytag;
|
|
|
|
extern crate libimagutil;
|
2016-11-01 19:06:38 +00:00
|
|
|
#[macro_use] extern crate version;
|
|
|
|
|
|
|
|
use clap::Shell;
|
|
|
|
use libimagrt::runtime::Runtime;
|
|
|
|
|
2016-11-05 10:25:25 +00:00
|
|
|
/// This macro generates mods with the given '$modulename',
|
|
|
|
/// whose content is the file given with `$path`.
|
|
|
|
/// In this case, It is used specifically to include the
|
|
|
|
/// `ui.rs` files of the imag binaries.
|
|
|
|
/// The imag project (accidentally?) followed the convention
|
|
|
|
/// to write a `ui.rs` containing the function
|
|
|
|
/// `fn build_ui(app : App) -> App`.
|
|
|
|
/// This macro allows us to use the same named functions by
|
|
|
|
/// putting them each into their own module.
|
|
|
|
macro_rules! gen_mods_buildui {
|
|
|
|
($(($path:expr, $modulename:ident)$(,)*)*) => (
|
2016-11-01 19:06:38 +00:00
|
|
|
$(
|
2016-11-05 10:25:25 +00:00
|
|
|
mod $modulename {
|
|
|
|
include!($path);
|
2016-11-01 19:06:38 +00:00
|
|
|
}
|
|
|
|
)*
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-11-05 10:25:25 +00:00
|
|
|
/// This macro reduces boilerplate code.
|
|
|
|
///
|
|
|
|
/// For example: `build_subcommand!("counter", imagcounter)`
|
|
|
|
/// will result in the following code:
|
|
|
|
/// ```ignore
|
|
|
|
/// imagcounter::build_ui(Runtime::get_default_cli_builder(
|
|
|
|
/// "counter",
|
|
|
|
/// &version!()[..],
|
|
|
|
/// "counter"))
|
|
|
|
/// ```
|
2016-11-05 10:52:23 +00:00
|
|
|
/// As for the `&version!()[..]` part, it does not matter
|
|
|
|
/// which version the subcommand is getting here, as the
|
|
|
|
/// output of this script is a completion script, which
|
|
|
|
/// does not contain information about the version at all.
|
2016-11-05 10:09:42 +00:00
|
|
|
macro_rules! build_subcommand {
|
|
|
|
($name:expr, $module:ident) => (
|
|
|
|
$module::build_ui(Runtime::get_default_cli_builder(
|
|
|
|
$name,
|
|
|
|
&version!()[..],
|
|
|
|
$name))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-11-05 10:25:25 +00:00
|
|
|
// Actually generates the module.
|
|
|
|
gen_mods_buildui!(
|
2016-11-02 18:43:27 +00:00
|
|
|
("../imag-link/src/ui.rs", imaglink),
|
|
|
|
("../imag-notes/src/ui.rs", imagnotes),
|
|
|
|
("../imag-ref/src/ui.rs", imagref),
|
|
|
|
("../imag-store/src/ui.rs", imagstore),
|
|
|
|
("../imag-tag/src/ui.rs", imagtag),
|
|
|
|
("../imag-view/src/ui.rs", imagview)
|
2016-11-05 10:09:42 +00:00
|
|
|
);
|
2016-11-01 19:06:38 +00:00
|
|
|
|
|
|
|
fn main() {
|
2016-11-05 10:25:25 +00:00
|
|
|
// Make the `imag`-App...
|
2016-11-01 19:06:38 +00:00
|
|
|
let mut app = Runtime::get_default_cli_builder(
|
|
|
|
"imag",
|
|
|
|
&version!()[..],
|
2016-11-02 18:43:27 +00:00
|
|
|
"imag")
|
2016-11-05 10:25:25 +00:00
|
|
|
// and add all the subapps as subcommands.
|
2016-11-05 10:09:42 +00:00
|
|
|
.subcommand(build_subcommand!("link", imaglink))
|
|
|
|
.subcommand(build_subcommand!("notes", imagnotes))
|
|
|
|
.subcommand(build_subcommand!("ref", imagref))
|
|
|
|
.subcommand(build_subcommand!("store", imagstore))
|
|
|
|
.subcommand(build_subcommand!("tag", imagtag))
|
|
|
|
.subcommand(build_subcommand!("view", imagview));
|
|
|
|
|
2017-01-25 08:41:14 +00:00
|
|
|
let outdir = std::env::var("OUT_DIR").unwrap();
|
|
|
|
|
2016-11-05 10:25:25 +00:00
|
|
|
// Actually generates the completion files
|
2017-01-25 09:43:37 +00:00
|
|
|
app.gen_completions("imag", Shell::Bash, outdir.clone());
|
|
|
|
app.gen_completions("imag", Shell::Fish, outdir.clone());
|
2017-01-25 08:41:14 +00:00
|
|
|
app.gen_completions("imag", Shell::Zsh, outdir);
|
2016-11-01 19:06:38 +00:00
|
|
|
|
|
|
|
}
|
2016-11-05 10:09:42 +00:00
|
|
|
|