mirror of
https://github.com/moghtech/komodo.git
synced 2026-03-11 17:44:19 -05:00
gen periphery config with cli
This commit is contained in:
@@ -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::<String>("path")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("$HOME/.monitor/config.toml")
|
||||
.to_string();
|
||||
let port = sub_matches
|
||||
.get_one::<String>("port")
|
||||
.map(|p| p.as_str())
|
||||
.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,
|
||||
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) {}
|
||||
|
||||
|
||||
@@ -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 <PATH> "sets path of generated config file. default is '~/.monitor/config.toml'")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--port <PORT> "sets port periphery will run on. default is 9001")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--repo_dir <PATH> "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 <config_gen, start> <flags>'",
|
||||
);
|
||||
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 <config_gen, start_mongo, start> <flags>'")
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Submodule periphery/Users/max/monitor_repos/periphery deleted from b1e2328d54
Reference in New Issue
Block a user