diff --git a/cli/src/helpers.rs b/cli/src/helpers.rs index 07e4853ba..5c90b7a57 100644 --- a/cli/src/helpers.rs +++ b/cli/src/helpers.rs @@ -5,7 +5,7 @@ use std::{ use async_timing_util::Timelength; use clap::ArgMatches; -use monitor_types::{CoreConfig, MongoConfig}; +use monitor_types::{CoreConfig, MongoConfig, PeripheryConfig}; use rand::{distributions::Alphanumeric, Rng}; use serde::Serialize; @@ -57,14 +57,43 @@ pub fn gen_core_config(sub_matches: &ArgMatches) { write_to_toml(&path, config); - println!("core config has been generated ✅"); + println!("\ncore config has been generated ✅"); } pub fn start_mongo(sub_matches: &ArgMatches) {} pub fn start_core(sub_matches: &ArgMatches) {} -pub fn get_periphery_config(sub_matches: &ArgMatches) {} +pub fn gen_periphery_config(sub_matches: &ArgMatches) { + let path = sub_matches + .get_one::("path") + .map(|p| p.as_str()) + .unwrap_or("$HOME/.monitor/config.toml") + .to_string(); + let port = sub_matches + .get_one::("port") + .map(|p| p.as_str()) + .unwrap_or("9000") + .parse::() + .expect("invalid port"); + let repo_dir = sub_matches + .get_one::("repo_dir") + .map(|p| p.as_str()) + .unwrap_or("/repos") + .to_string(); + + let config = PeripheryConfig { + port, + repo_dir, + secrets: Default::default(), + github_accounts: Default::default(), + docker_accounts: Default::default(), + }; + + write_to_toml(&path, config); + + println!("\nperiphery config has been generated ✅"); +} pub fn start_periphery(sub_matches: &ArgMatches) {} diff --git a/cli/src/main.rs b/cli/src/main.rs index 461499d7e..383b73ce4 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -55,7 +55,22 @@ fn cli() -> Command { .subcommand_required(true) .arg_required_else_help(true) .allow_external_subcommands(true) - .subcommand(Command::new("config_gen").about("generate a periphery config")) + .subcommand( + Command::new("config_gen") + .about("generate a periphery config") + .arg( + arg!(--path "sets path of generated config file. default is '~/.monitor/config.toml'") + .required(false) + ) + .arg( + arg!(--port "sets port periphery will run on. default is 9001") + .required(false) + ) + .arg( + arg!(--repo_dir "sets folder that repos will be cloned into. default is /repos") + .required(false) + ) + ) .subcommand(Command::new("start").about("start up monitor periphery")), ) } @@ -80,7 +95,7 @@ fn main() { "invalid call, should be 'monitor_cli periphery '", ); match periphery_command { - ("config_gen", sub_matches) => get_periphery_config(sub_matches), + ("config_gen", sub_matches) => gen_periphery_config(sub_matches), ("start", sub_matches) => start_periphery(sub_matches), _ => { println!("invalid call, should be 'monitor_cli core '") diff --git a/lib/types/src/lib.rs b/lib/types/src/lib.rs index 098b0d477..b68acd07d 100644 --- a/lib/types/src/lib.rs +++ b/lib/types/src/lib.rs @@ -531,20 +531,18 @@ fn default_core_mongo_db_name() -> String { "monitor".to_string() } -#[derive(Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug)] pub struct PeripheryConfig { #[serde(default = "default_periphery_port")] pub port: u16, + #[serde(default = "default_repo_dir")] + pub repo_dir: String, #[serde(default)] - pub is_builder: bool, - #[serde(default)] - pub docker_accounts: DockerAccounts, + pub secrets: SecretsMap, #[serde(default)] pub github_accounts: GithubAccounts, #[serde(default)] - pub secrets: SecretsMap, - #[serde(default = "default_repo_dir")] - pub repo_dir: String, + pub docker_accounts: DockerAccounts, } fn default_periphery_port() -> u16 { diff --git a/periphery/Users/max/monitor_repos/periphery b/periphery/Users/max/monitor_repos/periphery deleted file mode 160000 index b1e2328d5..000000000 --- a/periphery/Users/max/monitor_repos/periphery +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b1e2328d54a41c213681d2012dff439d25dbe95e