-
Notifications
You must be signed in to change notification settings - Fork 38
/
start.rs.hbs
45 lines (39 loc) · 1.35 KB
/
start.rs.hbs
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
//! `start` subcommand - example of how to write a subcommand
/// App-local prelude includes `app_reader()`/`app_writer()`/`app_config()`
/// accessors along with logging macros. Customize as you see fit.
use crate::prelude::*;
use crate::config::{{~config_type~}};
use abscissa_core::{config, Clap, Command, FrameworkError, Runnable};
/// `start` subcommand
///
/// The `Clap` proc macro generates an option parser based on the struct
/// definition, and is defined in the `gumdrop` crate. See their documentation
/// for a more comprehensive example:
///
/// <https://docs.rs/clap/>
#[derive(Command, Debug, Clap)]
pub struct StartCmd {
/// To whom are we saying hello?
recipient: Vec<String>,
}
impl Runnable for StartCmd {
/// Start the application.
fn run(&self) {
let config = APP.config();
println!("Hello, {}!", &config.hello.recipient);
}
}
impl config::Override<{{~config_type~}}> for StartCmd {
// Process the given command line options, overriding settings from
// a configuration file using explicit flags taken from command-line
// arguments.
fn override_config(
&self,
mut config: {{config_type}},
) -> Result<{{config_type}}, FrameworkError> {
if !self.recipient.is_empty() {
config.hello.recipient = self.recipient.join(" ");
}
Ok(config)
}
}