|
1 |
| -use clap::{command, Parser, Subcommand, ValueHint}; |
| 1 | +pub mod action; |
2 | 2 |
|
3 |
| -#[derive(Parser, Debug)] |
4 |
| -#[command(version, about, long_about = None)] |
5 |
| -struct Args { |
6 |
| - /// run Articleman in development mode |
7 |
| - #[arg(short, long)] |
8 |
| - dev: bool, |
| 3 | +use clap::{builder::styling, crate_authors, crate_name, Command}; |
9 | 4 |
|
10 |
| - /// set a PostgreSQL connection string to use for this instance of Articleman |
11 |
| - #[arg(short = 'c', long, value_hint = ValueHint::Url)] |
12 |
| - database_connection: Option<String>, |
| 5 | +use self::action::Action; |
13 | 6 |
|
14 |
| - #[command(subcommand)] |
15 |
| - cmd: Commands, |
| 7 | +pub async fn gen_cmd_iface() -> Command { |
| 8 | + let styles = styling::Styles::styled() |
| 9 | + .header(styling::AnsiColor::Yellow.on_default() | styling::Effects::BOLD); |
| 10 | + Command::new(crate_name!()) |
| 11 | + .help_expected(true) |
| 12 | + .styles(styles) |
| 13 | + .author(crate_authors!(" and ")) |
| 14 | + .about("Articleman: The best project management tool on the planet.") |
| 15 | + .long_about("Articleman Oxide: The fastest API server for the best project management tool on the planet.") |
| 16 | + .subcommand(Command::new("server").subcommand(Command::new("start"))) |
16 | 17 | }
|
17 | 18 |
|
18 |
| -#[derive(Subcommand, Debug)] |
19 |
| -enum Commands { |
20 |
| - /// Manually run an ordinarily scheduled job |
21 |
| - Task { |
22 |
| - #[arg(short, long, required = true)] |
23 |
| - name: String, |
24 |
| - }, |
25 |
| -} |
26 |
| - |
27 |
| -pub async fn parse() { |
28 |
| - let args = Args::parse(); |
29 |
| - |
30 |
| - let is_dev = args.dev; |
| 19 | +pub async fn parse() -> Action { |
| 20 | + let iface = gen_cmd_iface().await; |
| 21 | + let matches = iface.get_matches(); |
31 | 22 |
|
32 |
| - println!("{is_dev}") |
| 23 | + if let Some((opt_name, opt_sub_matches)) = matches.subcommand() { |
| 24 | + match opt_name { |
| 25 | + "server" => { |
| 26 | + if let Some((server_opt_name, server_opt_sub_matches)) = |
| 27 | + opt_sub_matches.subcommand() |
| 28 | + { |
| 29 | + match server_opt_name { |
| 30 | + "start" => { |
| 31 | + return Action::ServerStart(action::ServerTarget::APIOnly) |
| 32 | + } |
| 33 | + _ => { |
| 34 | + return Action::NoOp; |
| 35 | + } |
| 36 | + } |
| 37 | + } else { |
| 38 | + return Action::NoOp; |
| 39 | + } |
| 40 | + } |
| 41 | + _ => return Action::NoOp, |
| 42 | + } |
| 43 | + } else { |
| 44 | + return Action::NoOp; |
| 45 | + } |
33 | 46 | }
|
0 commit comments