Setup basic CLI

This commit is contained in:
Starbeamrainbowlabs 2021-09-28 23:47:52 +01:00
commit f6563932c9
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 108 additions and 0 deletions

37
.gitignore vendored Normal file
View file

@ -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

18
Cargo.toml Normal file
View file

@ -0,0 +1,18 @@
[package]
name = "systemquery"
version = "0.1.0"
authors = ["Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>"]
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

53
src/main.rs Normal file
View file

@ -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);
}
}
}