mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-29 04:10:01 -05:00
add better error handing
This commit is contained in:
@@ -60,9 +60,39 @@ pub fn gen_core_config(sub_matches: &ArgMatches) {
|
||||
println!("\ncore config has been generated ✅");
|
||||
}
|
||||
|
||||
pub fn start_mongo(sub_matches: &ArgMatches) {}
|
||||
pub fn start_mongo(sub_matches: &ArgMatches) {
|
||||
let username = sub_matches
|
||||
.get_one::<String>("username")
|
||||
.map(|p| p.to_string());
|
||||
let password = sub_matches
|
||||
.get_one::<String>("password")
|
||||
.map(|p| p.to_string());
|
||||
|
||||
pub fn start_core(sub_matches: &ArgMatches) {}
|
||||
if (username.is_some() && password.is_none()) {
|
||||
println!("must provide --password if username is provided ❌");
|
||||
return;
|
||||
}
|
||||
if (username.is_none() && password.is_some()) {
|
||||
println!("must provide --username if password is provided ❌");
|
||||
return;
|
||||
}
|
||||
|
||||
// start mongo here
|
||||
|
||||
println!("\nmonitor mongo has been started up ✅")
|
||||
}
|
||||
|
||||
pub fn start_core(sub_matches: &ArgMatches) {
|
||||
let config_path = sub_matches
|
||||
.get_one::<String>("config_path")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("$HOME/.monitor/config.toml")
|
||||
.to_string();
|
||||
|
||||
// start core here
|
||||
|
||||
println!("\nmonitor core has been started up ✅");
|
||||
}
|
||||
|
||||
pub fn gen_periphery_config(sub_matches: &ArgMatches) {
|
||||
let path = sub_matches
|
||||
@@ -76,15 +106,10 @@ pub fn gen_periphery_config(sub_matches: &ArgMatches) {
|
||||
.unwrap_or("9000")
|
||||
.parse::<u16>()
|
||||
.expect("invalid port");
|
||||
let repo_dir = sub_matches
|
||||
.get_one::<String>("repo_dir")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("/repos")
|
||||
.to_string();
|
||||
|
||||
let config = PeripheryConfig {
|
||||
port,
|
||||
repo_dir,
|
||||
repo_dir: "/repos".to_string(),
|
||||
secrets: Default::default(),
|
||||
github_accounts: Default::default(),
|
||||
docker_accounts: Default::default(),
|
||||
@@ -95,7 +120,22 @@ pub fn gen_periphery_config(sub_matches: &ArgMatches) {
|
||||
println!("\nperiphery config has been generated ✅");
|
||||
}
|
||||
|
||||
pub fn start_periphery(sub_matches: &ArgMatches) {}
|
||||
pub fn start_periphery(sub_matches: &ArgMatches) {
|
||||
let config_path = sub_matches
|
||||
.get_one::<String>("config_path")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("$HOME/.monitor/config.toml")
|
||||
.to_string();
|
||||
let repo_dir = sub_matches
|
||||
.get_one::<String>("repo_dir")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("$HOME/.monitor/repos")
|
||||
.to_string();
|
||||
|
||||
// start periphery here
|
||||
|
||||
println!("\nmonitor periphery has been started up ✅");
|
||||
}
|
||||
|
||||
fn write_to_toml(path: &str, toml: impl Serialize) {
|
||||
fs::write(
|
||||
|
||||
@@ -20,7 +20,7 @@ fn cli() -> Command {
|
||||
.allow_external_subcommands(true)
|
||||
.subcommand(
|
||||
Command::new("config_gen")
|
||||
.about("generate a core config")
|
||||
.about("generate a core config file")
|
||||
.arg(
|
||||
arg!(--path <PATH> "sets path of generated config file. default is '~/.monitor/config.toml'")
|
||||
.required(false)
|
||||
@@ -46,8 +46,26 @@ fn cli() -> Command {
|
||||
.required(false)
|
||||
),
|
||||
)
|
||||
.subcommand(Command::new("start_mongo").about("start up a mongo for monitor"))
|
||||
.subcommand(Command::new("start").about("start up monitor core")),
|
||||
.subcommand(
|
||||
Command::new("start_mongo")
|
||||
.about("start up a local mongo container for monitor")
|
||||
.arg(
|
||||
arg!(--username <USERNAME> "specify the default (root) username for mongo. default is mongo with no auth")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--password <PASSWORD> "specify the default (root) password for mongo. default is mongo with no auth")
|
||||
.required(false)
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("start")
|
||||
.about("start up monitor core")
|
||||
.arg(
|
||||
arg!(--config_path <PATH> "specify the file path to use for config. default is ~/.monitor/config.toml")
|
||||
.required(false)
|
||||
)
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("periphery")
|
||||
@@ -57,7 +75,7 @@ fn cli() -> Command {
|
||||
.allow_external_subcommands(true)
|
||||
.subcommand(
|
||||
Command::new("config_gen")
|
||||
.about("generate a periphery config")
|
||||
.about("generate a periphery config file")
|
||||
.arg(
|
||||
arg!(--path <PATH> "sets path of generated config file. default is '~/.monitor/config.toml'")
|
||||
.required(false)
|
||||
@@ -66,12 +84,19 @@ fn cli() -> Command {
|
||||
arg!(--port <PORT> "sets port periphery will run on. default is 9001")
|
||||
.required(false)
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("start")
|
||||
.about("start up monitor periphery")
|
||||
.arg(
|
||||
arg!(--repo_dir <PATH> "sets folder that repos will be cloned into. default is /repos")
|
||||
arg!(--config_path <PATH> "specify the file path to use for config. default is ~/.monitor/config.toml")
|
||||
.required(false)
|
||||
)
|
||||
)
|
||||
.subcommand(Command::new("start").about("start up monitor periphery")),
|
||||
.arg(
|
||||
arg!(--repo_dir <PATH> "specify the folder on system to use as cloning destination. default is ~/.monitor/repos")
|
||||
.required(false)
|
||||
)
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -80,25 +105,25 @@ fn main() {
|
||||
|
||||
match matches.subcommand() {
|
||||
Some(("core", sub_matches)) => {
|
||||
let core_command = sub_matches.subcommand().expect("invalid call, should be 'monitor_cli core <config_gen, start_mongo, start> <flags>'");
|
||||
let core_command = sub_matches.subcommand().expect("\n❌ invalid call, should be 'monitor_cli core <config_gen, start_mongo, start> <flags>' ❌\n");
|
||||
match core_command {
|
||||
("config_gen", sub_matches) => gen_core_config(sub_matches),
|
||||
("start_mongo", sub_matches) => start_mongo(sub_matches),
|
||||
("start", sub_matches) => start_core(sub_matches),
|
||||
_ => {
|
||||
println!("invalid call, should be 'monitor_cli core <config_gen, start_mongo, start> <flags>'")
|
||||
println!("\n❌ invalid call, should be 'monitor_cli core <config_gen, start_mongo, start> <flags>' ❌\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(("periphery", sub_matches)) => {
|
||||
let periphery_command = sub_matches.subcommand().expect(
|
||||
"invalid call, should be 'monitor_cli periphery <config_gen, start> <flags>'",
|
||||
"\n❌ invalid call, should be 'monitor_cli periphery <config_gen, start> <flags>' ❌\n",
|
||||
);
|
||||
match periphery_command {
|
||||
("config_gen", sub_matches) => gen_periphery_config(sub_matches),
|
||||
("start", sub_matches) => start_periphery(sub_matches),
|
||||
_ => {
|
||||
println!("invalid call, should be 'monitor_cli core <config_gen, start_mongo, start> <flags>'")
|
||||
println!("\n❌ invalid call, should be 'monitor_cli periphery <config_gen, start> <flags>' ❌\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user