pub fn parse_args() -> Args {
    let args = App::new("nuker")
        .about("Cleans up AWS resources based on configurable Rules.")
        .version(VERSION.unwrap_or("unknown"))
        .subcommand(App::new("resource-types").about("Prints out supported resource types"))
        .arg(
            Arg::with_name("config-file")
                .long("config")
                .short("C")
                .value_name("config")
                // .required(true)
                .help("The config file to feed in.")
                .takes_value(true),
        )
        .arg(
            Arg::with_name("region")
                .long("region")
                .help(
                    "Which regions to enforce the rules in. Default is the rules will be \
                    enforced across all the regions.",
                )
                .takes_value(true)
                .multiple(true)
                .number_of_values(1),
        )
        .arg(
            Arg::with_name("target")
                .long("target")
                .help(
                    "Services to include from rules enforcement. This will take precedence \
                over the configuration file.",
                )
                .takes_value(true)
                .multiple(true)
                .number_of_values(1),
        )
        .arg(
            Arg::with_name("exclude")
                .long("exclude")
                .help(
                    "Services to exclude from rules enforcement. This will take precedence \
                over the configuration file.",
                )
                .takes_value(true)
                .multiple(true)
                .number_of_values(1)
                .conflicts_with("target"),
        )
        .arg(
            Arg::with_name("profile")
                .long("profile")
                .help(
                    "Named Profile to use for authenticating with AWS. If the profile is \
                    *not* set, the credentials will be sourced in the following order: \n\
                    1. Environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY \n\
                    2. AWS credentials file. Usually located at ~/.aws/credentials.\n\
                    3. IAM instance profile",
                )
                .takes_value(true),
        )
        .arg(Arg::with_name("no-dry-run").long("no-dry-run").help(
            "Disables the dry run behavior, which just lists the resources that are \
                    being cleaned but not actually delete them. Enabling this option will disable \
                    dry run behavior and deletes the resources.",
        ))
        .arg(
            Arg::with_name("force")
                .long("force")
                .help("Does not prompt for confirmation when dry run is disabled"),
        )
        .arg(
            Arg::with_name("verbose")
                .short("v")
                .multiple(true)
                .help("Turn on verbose output."),
        )
        .get_matches();

    if let Some(ref _matches) = args.subcommand_matches("resource-types") {
        for r in Client::iter() {
            print!("{} ", r.name());
        }
        ::std::process::exit(0);
    }

    if !args.is_present("config-file") {
        panic!("--config <config> is a required parameter");
    }

    let verbose = if args.is_present("verbose") {
        args.occurrences_of("verbose")
    } else {
        0
    };

    let dry_run = if args.is_present("no-dry-run") {
        false
    } else {
        true
    };

    let force = if args.is_present("force") {
        true
    } else {
        false
    };

    let regions: Vec<&str> = if args.is_present("region") {
        args.values_of("region").unwrap().collect()
    } else {
        vec![]
    };

    let targets: Option<Vec<Client>> = if args.is_present("target") {
        Some(
            args.values_of("target")
                .unwrap()
                .map(|t| Client::from_str(t).unwrap())
                .collect(),
        )
    } else {
        None
    };

    let exclude: Option<Vec<Client>> = if args.is_present("exclude") {
        Some(
            args.values_of("exclude")
                .unwrap()
                .map(|e| Client::from_str(e).unwrap())
                .collect(),
        )
    } else {
        None
    };

    Args {
        config: args.value_of("config-file").unwrap().to_string(),
        regions: regions.iter().map(|r| r.to_string()).collect(),
        profile: args.value_of("profile").map(|s| s.to_owned()),
        targets,
        exclude,
        dry_run,
        force,
        verbose,
        version: VERSION.unwrap_or("unknown").to_string(),
    }
}
/// Parse the command line arguments for nuker executable
Parse the command line arguments for nuker executable
Parse the command line arguments for nuker executable
pub fn parse_args() -> Args {
    let args = App::new("nuker")
        .about("Cleans up AWS resources based on configurable Rules.")
        .version(VERSION.unwrap_or("unknown"))
        .subcommand(App::new("resource-types").about("Prints out supported resource types"))
        .arg(
            Arg::with_name("config-file")
                .long("config")
                .short("C")
                .value_name("config")
                // .required(true)
                .help("The config file to feed in.")
                .takes_value(true),
        )
        .arg(
            Arg::with_name("region")
                .long("region")
                .help(
                    "Which regions to enforce the rules in. Default is the rules will be \
                    enforced across all the regions.",
                )
                .takes_value(true)
                .multiple(true)
                .number_of_values(1),
        )
        .arg(
            Arg::with_name("target")
                .long("target")
                .help(
                    "Services to include from rules enforcement. This will take precedence \
                over the configuration file.",
                )
                .takes_value(true)
                .multiple(true)
                .number_of_values(1),
        )
        .arg(
            Arg::with_name("exclude")
                .long("exclude")
                .help(
                    "Services to exclude from rules enforcement. This will take precedence \
                over the configuration file.",
                )
                .takes_value(true)
                .multiple(true)
                .number_of_values(1)
                .conflicts_with("target"),
        )
        .arg(
            Arg::with_name("profile")
                .long("profile")
                .help(
                    "Named Profile to use for authenticating with AWS. If the profile is \
                    *not* set, the credentials will be sourced in the following order: \n\
                    1. Environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY \n\
                    2. AWS credentials file. Usually located at ~/.aws/credentials.\n\
                    3. IAM instance profile",
                )
                .takes_value(true),
        )
        .arg(Arg::with_name("no-dry-run").long("no-dry-run").help(
            "Disables the dry run behavior, which just lists the resources that are \
                    being cleaned but not actually delete them. Enabling this option will disable \
                    dry run behavior and deletes the resources.",
        ))
        .arg(
            Arg::with_name("force")
                .long("force")
                .help("Does not prompt for confirmation when dry run is disabled"),
        )
        .arg(
            Arg::with_name("verbose")
                .short("v")
                .multiple(true)
                .help("Turn on verbose output."),
        )
        .get_matches();
    if let Some(ref _matches) = args.subcommand_matches("resource-types") {
        for r in Client::iter() {
            print!("{} ", r.name());
        }
        ::std::process::exit(0);
    }
    if !args.is_present("config-file") {
        panic!("--config <config> is a required parameter");
    }
    let verbose = if args.is_present("verbose") {
        args.occurrences_of("verbose")
    } else {
        0
    };
    let dry_run = if args.is_present("no-dry-run") {
        false
    } else {
        true
    };
    let force = if args.is_present("force") {
        true
    } else {
        false
    };
    let regions: Vec<&str> = if args.is_present("region") {
        args.values_of("region").unwrap().collect()
    } else {
        vec![]
    };
    let targets: Option<Vec<Client>> = if args.is_present("target") {
        Some(
            args.values_of("target")
                .unwrap()
                .map(|t| Client::from_str(t).unwrap())
                .collect(),
        )
    } else {
        None
    };
    let exclude: Option<Vec<Client>> = if args.is_present("exclude") {
        Some(
            args.values_of("exclude")
                .unwrap()
                .map(|e| Client::from_str(e).unwrap())
                .collect(),
        )
    } else {
        None
    };
    Args {
        config: args.value_of("config-file").unwrap().to_string(),
        regions: regions.iter().map(|r| r.to_string()).collect(),
        profile: args.value_of("profile").map(|s| s.to_owned()),
        targets,
        exclude,
        dry_run,
        force,
        verbose,
        version: VERSION.unwrap_or("unknown").to_string(),
    }
}
pub fn parse_args ( ) -> Args { let args = App :: new ( " " ) . about ( " " ) . version ( VERSION . unwrap_or ( " " ) ) . subcommand ( App :: new ( " " ) . about ( " " ) ) . arg ( Arg :: with_name ( " " ) . long ( " " ) . short ( " " ) . value_name ( " " ) // .required(true) . help ( " " ) . takes_value ( true ) , ) . arg ( Arg :: with_name ( " " ) . long ( " " ) . help ( " \
 " , ) . takes_value ( true ) . multiple ( true ) . number_of_values ( 1 ) , ) . arg ( Arg :: with_name ( " " ) . long ( " " ) . help ( " \
 " , ) . takes_value ( true ) . multiple ( true ) . number_of_values ( 1 ) , ) . arg ( Arg :: with_name ( " " ) . long ( " " ) . help ( " \
 " , ) . takes_value ( true ) . multiple ( true ) . number_of_values ( 1 ) . conflicts_with ( " " ) , ) . arg ( Arg :: with_name ( " " ) . long ( " " ) . help ( " \
 \n \
 \n \
 \n \
 " , ) . takes_value ( true ) , ) . arg ( Arg :: with_name ( " " ) . long ( " " ) . help ( " \
 \
 " , ) ) . arg ( Arg :: with_name ( " " ) . long ( " " ) . help ( " " ) , ) . arg ( Arg :: with_name ( " " ) . short ( " " ) . multiple ( true ) . help ( " " ) , ) . get_matches ( ) ; if let Some ( ref _matches ) = args . subcommand_matches ( " " ) { for r in Client :: iter ( ) { print ! ( " " r name ( ) ) ; } :: std :: process :: exit ( 0 ) ; } if ! args . is_present ( " " ) { panic ! ( " " ) ; } let verbose = if args . is_present ( " " ) { args . occurrences_of ( " " ) } else { 0 } ; let dry_run = if args . is_present ( " " ) { false } else { true } ; let force = if args . is_present ( " " ) { true } else { false } ; let regions : Vec < & str > = if args . is_present ( " " ) { args . values_of ( " " ) . unwrap ( ) . collect ( ) } else { vec ! [ ] } ; let targets : Option < Vec < Client > > = if args . is_present ( " " ) { Some ( args . values_of ( " " ) . unwrap ( ) . map ( | t | Client :: from_str ( t ) . unwrap ( ) ) . collect ( ) , ) } else { None } ; let exclude : Option < Vec < Client > > = if args . is_present ( " " ) { Some ( args . values_of ( " " ) . unwrap ( ) . map ( | e | Client :: from_str ( e ) . unwrap ( ) ) . collect ( ) , ) } else { None } ; Args { config : args . value_of ( " " ) . unwrap ( ) . to_string ( ) , regions : regions . iter ( ) . map ( | r | r . to_string ( ) ) . collect ( ) , profile : args . value_of ( " " ) . map ( | s | s . to_owned ( ) ) , targets , exclude , dry_run , force , verbose , version : VERSION . unwrap_or ( " " ) . to_string ( ) , } }
Parse the command line arguments for nuker executable
Parse the command line arguments for nuker executable