Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit b7deb80

Browse files
committed
add cli start functionality, use clap::Command instead of derive
1 parent 489f954 commit b7deb80

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

backend/src/cli/action.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub enum Action {
2+
ServerStart(ServerTarget),
3+
ServerStop(ServerTarget),
4+
5+
NoOp
6+
}
7+
8+
pub enum ServerTarget {
9+
APIOnly,
10+
FrontendOnly,
11+
AllServices,
12+
}

backend/src/cli/mod.rs

+39-26
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
1-
use clap::{command, Parser, Subcommand, ValueHint};
1+
pub mod action;
22

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};
94

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;
136

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")))
1617
}
1718

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();
3122

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+
}
3346
}

0 commit comments

Comments
 (0)