summaryrefslogtreecommitdiffstats
path: root/bin/core/imag/build.rs
blob: c7675ff22bebc512fd1bb69efea1090ff24d25d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// 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
//

extern crate clap;
extern crate libimagrt;
extern crate libimagentrytag;
extern crate libimagutil;

use clap::Shell;
use libimagrt::runtime::Runtime;

#[allow(unused_imports)]
use libimagrt::application::ImagApplication;

#[cfg(feature = "cc-imag-annotate")]
extern crate libimagannotatecmd;
#[cfg(feature = "cc-imag-create")]
extern crate libimagcreatecmd;
#[cfg(feature = "cc-imag-diagnostics")]
extern crate libimagdiagnosticscmd;
#[cfg(feature = "cc-imag-edit")]
extern crate libimageditcmd;
#[cfg(feature = "cc-imag-gps")]
extern crate libimaggpscmd;
#[cfg(feature = "cc-imag-grep")]
extern crate libimaggrepcmd;
#[cfg(feature = "cc-imag-ids")]
extern crate libimagidscmd;
#[cfg(feature = "cc-imag-init")]
extern crate libimaginitcmd;
#[cfg(feature = "cc-imag-link")]
extern crate libimaglinkcmd;
#[cfg(feature = "cc-imag-mv")]
extern crate libimagmvcmd;
#[cfg(feature = "cc-imag-ref")]
extern crate libimagrefcmd;
#[cfg(feature = "cc-imag-store")]
extern crate libimagstorecmd;
#[cfg(feature = "cc-imag-tag")]
extern crate libimagtagcmd;
#[cfg(feature = "cc-imag-view")]
extern crate libimagviewcmd;
#[cfg(feature = "cc-imag-bookmark")]
extern crate libimagbookmarkfrontend;
#[cfg(feature = "cc-imag-calendar")]
extern crate libimagcalendarfrontend;
#[cfg(feature = "cc-imag-contact")]
extern crate libimagcontactfrontend;
#[cfg(feature = "cc-imag-diary")]
extern crate libimagdiaryfrontend;
#[cfg(feature = "cc-imag-habit")]
extern crate libimaghabitfrontend;
#[cfg(feature = "cc-imag-log")]
extern crate libimaglogfrontend;
#[cfg(feature = "cc-imag-mail")]
extern crate libimagmailfrontend;
#[cfg(feature = "cc-imag-notes")]
extern crate libimagnotesfrontend;
#[cfg(feature = "cc-imag-timetrack")]
extern crate libimagtimetrackfrontend;
#[cfg(feature = "cc-imag-todo")]
extern crate libimagtodofrontend;

/// This macro reduces boilerplate code.
///
/// For example: `build_subcommand!("counter", libbinimagcounter, ImagCounter)`
/// will result in the following code:
/// ```ignore
/// ImagCounter::build_cli(Runtime::get_default_cli_builder(
///     "counter",
///     "abc",
///     "counter"))
/// ```
/// As for the `"abc"` 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.
#[allow(unused_macros)]
macro_rules! build_subcommand {
    ($name:expr, $lib:ident, $implementor:ident) => (
        $lib::$implementor::build_cli(Runtime::get_default_cli_builder($name, "abc", $name))
    )
}

fn main() {
    // Make the `imag`-App...
    let app = Runtime::get_default_cli_builder(
        "imag",
        "abc",
        "imag");

    // and add all the subapps as subcommands.
    // TODO: This feels tedious, can we automate this?
    #[cfg(feature = "cc-imag-annotate")]
    let app = app.subcommand(build_subcommand!("annotate",    libimagannotatecmd, ImagAnnotate));
    #[cfg(feature = "cc-imag-create")]
    let app = app.subcommand(build_subcommand!("create",      libimagcreatecmd, ImagCreate));
    #[cfg(feature = "cc-imag-diagnostics")]
    let app = app.subcommand(build_subcommand!("diagnostics", libimagdiagnosticscmd, ImagDiagnostics));
    #[cfg(feature = "cc-imag-edit")]
    let app = app.subcommand(build_subcommand!("edit",        libimageditcmd, ImagEdit));
    #[cfg(feature = "cc-imag-gps")]
    let app = app.subcommand(build_subcommand!("gps",         libimaggpscmd, ImagGps));
    #[cfg(feature = "cc-imag-grep")]
    let app = app.subcommand(build_subcommand!("grep",        libimaggrepcmd, ImagGrep));
    #[cfg(feature = "cc-imag-ids")]
    let app = app.subcommand(build_subcommand!("ids",         libimagidscmd, ImagIds));
    #[cfg(feature = "cc-imag-init")]
    let app = app.subcommand(build_subcommand!("init",        libimaginitcmd, ImagInit));
    #[cfg(feature = "cc-imag-link")]
    let app = app.subcommand(build_subcommand!("link",        libimaglinkcmd, ImagLink));
    #[cfg(feature = "cc-imag-mv")]
    let app = app.subcommand(build_subcommand!("mv",          libimagmvcmd, ImagMv));
    #[cfg(feature = "cc-imag-ref")]
    let app = app.subcommand(build_subcommand!("ref",         libimagrefcmd, ImagRef));
    #[cfg(feature = "cc-imag-store")]
    let app = app.subcommand(build_subcommand!("store",       libimagstorecmd, ImagStore));
    #[cfg(feature = "cc-imag-tag")]
    let app = app.subcommand(build_subcommand!("tag",         libimagtagcmd, ImagTag));
    #[cfg(feature = "cc-imag-view")]
    let app = app.subcommand(build_subcommand!("view",         libimagviewcmd, ImagView));
    #[cfg(feature = "cc-imag-bookmark")]
    let app = app.subcommand(build_subcommand!("bookmark",    libimagbookmarkfrontend, ImagBookmark));
    #[cfg(feature = "cc-imag-calendar")]
    let app = app.subcommand(build_subcommand!("calendar",    libimagcalendarfrontend, ImagCalendar));
    #[cfg(feature = "cc-imag-contact")]
    let app = app.subcommand(build_subcommand!("contact",     libimagcontactfrontend, ImagContact));
    #[cfg(feature = "cc-imag-diary")]
    let app = app.subcommand(build_subcommand!("diary",       libimagdiaryfrontend, ImagDiary));
    #[cfg(feature = "cc-imag-habit")]
    let app = app.subcommand(build_subcommand!("habit",       libimaghabitfrontend, ImagHabit));
    #[cfg(feature = "cc-imag-log")]
    let app = app.subcommand(build_subcommand!("log",         libimaglogfrontend, ImagLog));
    #[cfg(feature = "cc-imag-mail")]
    let app = app.subcommand(build_subcommand!("mail",        libimagmailfrontend, ImagMail));
    #[cfg(feature = "cc-imag-notes")]
    let app = app.subcommand(build_subcommand!("notes",       libimagnotesfrontend, ImagNotes));
    #[cfg(feature = "cc-imag-timetrack")]
    let app = app.subcommand(build_subcommand!("timetrack",   libimagtimetrackfrontend, ImagTimetrack));
    #[cfg(feature = "cc-imag-todo")]
    let app = app.subcommand(build_subcommand!("todo",        libimagtodofrontend, ImagTodo));

    let mut app = app;
    // Actually generates the completion files
    app.gen_completions("imag", Shell::Bash, "../../../target/");
    app.gen_completions("imag", Shell::Fish, "../../../target/");
    app.gen_completions("imag", Shell::Zsh,  "../../../target/");
}