From f6563932c9c7c20d1c15e237be35baed8175316c Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 28 Sep 2021 23:47:52 +0100 Subject: [PATCH] Setup basic CLI --- .gitignore | 37 +++++++++++++++++++++++++++++++++++++ Cargo.toml | 18 ++++++++++++++++++ src/main.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ff58a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +/target + +# Created by https://www.toptal.com/developers/gitignore/api/rust,git +# Edit at https://www.toptal.com/developers/gitignore?templates=rust,git + +### Git ### +# Created by git for backups. To disable backups in Git: +# $ git config --global mergetool.keepBackup false +*.orig + +# Created by git when using merge tools for conflicts +*.BACKUP.* +*.BASE.* +*.LOCAL.* +*.REMOTE.* +*_BACKUP_*.txt +*_BASE_*.txt +*_LOCAL_*.txt +*_REMOTE_*.txt + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# End of https://www.toptal.com/developers/gitignore/api/rust,git diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f583062 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "systemquery" +version = "0.1.0" +authors = ["Starbeamrainbowlabs "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +log = "0.4" # Apparently Rust has an entire logging setup - this is the base crate +pretty_env_logger = "0.4" # The logging implementation we've chosen for the above + + +clap = "2" # CLI argument parser + + +psk-client = { version = "0.1", features = ["vendored-openssl"] } # Pre-shared key TLS support diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..427c398 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,53 @@ +#[macro_use] +extern crate clap; +extern crate pretty_env_logger; + +use std::process; + +use clap::{ App, AppSettings, Arg, SubCommand }; + +fn main() { + // Initialise the logging system + pretty_env_logger::init(); + + let mut cli = App::new("systemquery") + .version(crate_version!()) + .author("Starbeamrainbowlabs") + .about("Distributed system information query tool") + .global_settings(&[ AppSettings::ColoredHelp ]) + .subcommand(SubCommand::with_name("agent") + .about("Starts the systemquery agent") + .arg(Arg::with_name("config") + .short("c").long("config") + .value_name("path/to/config.toml") + .help("Specifies the config file location") + .takes_value(true) + .default_value("/etc/systemquery/systemquery.toml"))) + .subcommand(SubCommand::with_name("query") + .about("Query the cluster [requires agent to be running on this host]") + .arg(Arg::with_name("address") + .short("a").long("address") + .takes_value(true) + .help("Address of the agent to connect to") + .takes_value(true) + .default_value("unix-abstract:systemquery"))); + let args = cli.clone().get_matches(); + + match args.subcommand_name() { + Some("agent") => { + println!("Coming soon :-)"); + }, + Some("query") => { + println!("Coming soon :-)"); + }, + None => { + cli.print_help().ok(); + println!("\n"); + process::exit(0); + }, + _ => { + println!("Error: Unknown subcommand {}", args.subcommand_name().unwrap()); + process::exit(1); + } + } +}