Skip to content

Commit

Permalink
feat: reworked the input args
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexsJones committed Nov 2, 2023
1 parent feb1c5e commit ad77427
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/analyze/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, enable_json: &bool, explain: &bool) {
let mut conf: Conf = config::Conf {
cloud: String::new(),
stored_advice: HashMap::new(),
Expand Down Expand Up @@ -40,7 +40,7 @@ pub async fn run_analysis(args: &Args) {
let (tx, rx): (Sender<Vec<AnalysisResults>>, Receiver<Vec<AnalysisResults>>) = mpsc::channel();
let analyzers: Vec<Box<dyn Analyzer>> = analyzer::generate_analyzers(config.clone());

match &args.analyzer {
match selected_analyzer {
Some(analyzer_arg) => {
let filtered_analyzer = &analyzers
.iter()
Expand Down Expand Up @@ -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();
}
}
Expand Down
40 changes: 29 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::Parser;
use clap::{Parser, Subcommand};
mod analyze;
mod analyzer;
mod config;
Expand All @@ -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<String>,
#[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<Commands>,
}
#[derive(Subcommand)]
enum Commands {
/// Run AWS account analysis
Analyze {
#[arg(short, long, long_help="Select a single analyzer")]
analyzer: Option<String>,
#[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");
}
}

}

0 comments on commit ad77427

Please sign in to comment.