From ad7742749873977dfe31694eb6decdeca74ac168 Mon Sep 17 00:00:00 2001 From: Alex Jones Date: Thu, 2 Nov 2023 15:38:08 +0000 Subject: [PATCH] feat: reworked the input args --- README.md | 6 +++--- src/analyze/mod.rs | 12 ++++++------ src/main.rs | 40 +++++++++++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 73e26a4..40e9e5b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Isotope scans AWS services and makes suggestions on how to improve them using AW ### Example ``` -❯ isotope --explain=true +❯ isotope analze --explain Current AWS region: eu-west-2 Running STS analyzer Running S3 analyzer @@ -54,13 +54,13 @@ export BEDROCK_REGION="eu-central-1" ( e.g. us-east-1,us-west-2, ap-southeast-1 2. Run all isotope analyzers ``` -isotope +isotope analyze ``` Optionally for a single analyzer ``` -isotope -a S3 +isotope analyze -a S3 ``` ### Analyzers diff --git a/src/analyze/mod.rs b/src/analyze/mod.rs index 9a155ec..278b5ee 100644 --- a/src/analyze/mod.rs +++ b/src/analyze/mod.rs @@ -11,7 +11,7 @@ use std::collections::HashMap; use std::sync::mpsc; use std::sync::mpsc::{Receiver, Sender}; -pub async fn run_analysis(args: &Args) { +pub async fn run_analysis(selected_analyzer: &Option, enable_json: &bool, explain: &bool) { let mut conf: Conf = config::Conf { cloud: String::new(), stored_advice: HashMap::new(), @@ -40,7 +40,7 @@ pub async fn run_analysis(args: &Args) { let (tx, rx): (Sender>, Receiver>) = mpsc::channel(); let analyzers: Vec> = analyzer::generate_analyzers(config.clone()); - match &args.analyzer { + match selected_analyzer { Some(analyzer_arg) => { let filtered_analyzer = &analyzers .iter() @@ -126,15 +126,15 @@ pub async fn run_analysis(args: &Args) { } } - if args.json { + if *enable_json { let mut p = outputs::Processor::new( processed_results, - Some(outputs::Configuration::new(args.json)), - args.explain, + Some(outputs::Configuration::new(*enable_json)), + *explain, ); p.print(); } else { - let mut p = outputs::Processor::new(processed_results, None, args.explain); + let mut p = outputs::Processor::new(processed_results, None, *explain); p.print(); } } diff --git a/src/main.rs b/src/main.rs index 01ff589..0d5c101 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use clap::Parser; +use clap::{Parser, Subcommand}; mod analyze; mod analyzer; mod config; @@ -13,21 +13,39 @@ const CARGO_PKG_DESCRIPTION: &str = "Isotope allows for the debugging of AWS ser const CARGO_PKG_AUTHORS: &str = "AlexsJones"; const CARGO_PKG_VERSION: &str = "0.0.3"; -#[derive(Parser, Debug)] +#[derive(Parser)] #[command(author, version, about, long_about = None)] pub struct Args { - #[arg(short, long, long_help="Select a single analyzer")] - analyzer: Option, - #[arg(short, long, long_help="Enable debug logging")] - debug: bool, - #[arg(short, long, long_help="Print out results in JSON format")] - json: bool, - #[arg(short,long, long_help="Use Bedrock AI to assist in remediation of issues")] - explain: bool, + #[command(subcommand)] + command: Option, +} +#[derive(Subcommand)] +enum Commands { + /// Run AWS account analysis + Analyze { + #[arg(short, long, long_help="Select a single analyzer")] + analyzer: Option, + #[arg(short, long, long_help="Enable debug logging")] + debug: bool, + #[arg(short, long, long_help="Print out results in JSON format")] + json: bool, + #[arg(short,long, long_help="Use Bedrock AI to assist in remediation of issues")] + explain: bool, + }, } #[tokio::main] async fn main() { let args = Args::parse(); - analyze::run_analysis(&args).await; + match &args.command { + Some(Commands::Analyze { analyzer, debug, json, explain}) => { + + + analyze::run_analysis(analyzer,json,explain).await; + } + None => { + println!("Default subcommand"); + } + } + }