fn parse_parameters() -> Result<Config, ExitCodes> {
    let app = App::new("axfrnotify")
        .version(VERSION)
        .about("Send an NOTIFY message to a secondary name server to initiate a zone refresh for a specific domain name.")
        .arg(Arg::with_name("retries")
            .takes_value(true)
            .short("r")
            .long("retries")
            .value_name("retries")
            .help("Set the number of retries if notification fails; default is 0"))
        .arg(Arg::with_name("secondary")
            .takes_value(true)
            .short("s")
            .long("secondary")
            .value_name("IP or host name")
            .help("Set the secondary name server to notify; default is 127.0.0.1"))
        .arg(Arg::with_name("port")
            .takes_value(true)
            .short("p")
            .long("port")
            .value_name("port")
            .help("Set the secondary's port; default is 53"))
        .arg(Arg::with_name("record_type")
            .takes_value(true)
            .short("t")
            .long("type")
            .value_name("record_type")
            .help("Set the record type to send (A, AAAA, CHAME, MX, NS, PTR, SOA, SRV, TXT, ANY, AXFR); default is SOA"))
        .arg(Arg::with_name("domain")
            .takes_value(true)
            .required(true)
            .value_name("domain name")
            .help("Domain name to notify about"))
        .arg(Arg::with_name("verbose")
            .short("v")
            .help("Set verbose output"))
        ;
    let cli_args = app.get_matches();

    let verbose = cli_args.is_present("verbose");
    let secondary = cli_args.value_of("secondary").unwrap_or("127.0.0.1");
    let retries = if let Ok(retries) = cli_args.value_of("retries").unwrap_or("0").parse::<u16>() {
        retries
    } else {
        let msg = format!("'{}' is not a valid number of retries.", cli_args.value_of("retries").unwrap());
        return Err(ExitCodes::InputError(msg));
    };
    let port = if let Ok(port) = cli_args.value_of("port").unwrap_or("53").parse::<u16>() {
        port
    } else {
        let msg = format!("'{}' is not a valid port number.", cli_args.value_of("port").unwrap());
        return Err(ExitCodes::InputError(msg));
    };
    let record_type = if let Ok(record_type) = RecordType::from_str(cli_args.value_of("record_type").unwrap_or("SOA")) {
        record_type
    } else {
        let msg = format!("'{}' is not a valid record type.", cli_args.value_of("record_type").unwrap());
        return Err(ExitCodes::InputError(msg));
    };
    let domain_name = cli_args.value_of("domain").unwrap();

    Ok(Config { retries: retries, secondary: secondary.to_string(), port: port, record_type: record_type, domain_name: domain_name.to_string(), verbose: verbose })
}
/// Parses the command line parameters and creates a new `Config`.
Parses the command line parameters and creates a new `Config`.
Parses the command line parameters and creates a new ` Config ` .
fn parse_parameters() -> Result<Config, ExitCodes> {
    let app = App::new("axfrnotify")
        .version(VERSION)
        .about("Send an NOTIFY message to a secondary name server to initiate a zone refresh for a specific domain name.")
        .arg(Arg::with_name("retries")
            .takes_value(true)
            .short("r")
            .long("retries")
            .value_name("retries")
            .help("Set the number of retries if notification fails; default is 0"))
        .arg(Arg::with_name("secondary")
            .takes_value(true)
            .short("s")
            .long("secondary")
            .value_name("IP or host name")
            .help("Set the secondary name server to notify; default is 127.0.0.1"))
        .arg(Arg::with_name("port")
            .takes_value(true)
            .short("p")
            .long("port")
            .value_name("port")
            .help("Set the secondary's port; default is 53"))
        .arg(Arg::with_name("record_type")
            .takes_value(true)
            .short("t")
            .long("type")
            .value_name("record_type")
            .help("Set the record type to send (A, AAAA, CHAME, MX, NS, PTR, SOA, SRV, TXT, ANY, AXFR); default is SOA"))
        .arg(Arg::with_name("domain")
            .takes_value(true)
            .required(true)
            .value_name("domain name")
            .help("Domain name to notify about"))
        .arg(Arg::with_name("verbose")
            .short("v")
            .help("Set verbose output"))
        ;
    let cli_args = app.get_matches();
    let verbose = cli_args.is_present("verbose");
    let secondary = cli_args.value_of("secondary").unwrap_or("127.0.0.1");
    let retries = if let Ok(retries) = cli_args.value_of("retries").unwrap_or("0").parse::<u16>() {
        retries
    } else {
        let msg = format!("'{}' is not a valid number of retries.", cli_args.value_of("retries").unwrap());
        return Err(ExitCodes::InputError(msg));
    };
    let port = if let Ok(port) = cli_args.value_of("port").unwrap_or("53").parse::<u16>() {
        port
    } else {
        let msg = format!("'{}' is not a valid port number.", cli_args.value_of("port").unwrap());
        return Err(ExitCodes::InputError(msg));
    };
    let record_type = if let Ok(record_type) = RecordType::from_str(cli_args.value_of("record_type").unwrap_or("SOA")) {
        record_type
    } else {
        let msg = format!("'{}' is not a valid record type.", cli_args.value_of("record_type").unwrap());
        return Err(ExitCodes::InputError(msg));
    };
    let domain_name = cli_args.value_of("domain").unwrap();
    Ok(Config { retries: retries, secondary: secondary.to_string(), port: port, record_type: record_type, domain_name: domain_name.to_string(), verbose: verbose })
}
fn parse_parameters ( ) -> Result < Config , ExitCodes > { let app = App :: new ( " " ) . version ( VERSION ) . about ( " " ) . arg ( Arg :: with_name ( " " ) . takes_value ( true ) . short ( " " ) . long ( " " ) . value_name ( " " ) . help ( " " ) ) . arg ( Arg :: with_name ( " " ) . takes_value ( true ) . short ( " " ) . long ( " " ) . value_name ( " " ) . help ( " " ) ) . arg ( Arg :: with_name ( " " ) . takes_value ( true ) . short ( " " ) . long ( " " ) . value_name ( " " ) . help ( " " ) ) . arg ( Arg :: with_name ( " " ) . takes_value ( true ) . short ( " " ) . long ( " " ) . value_name ( " " ) . help ( " " ) ) . arg ( Arg :: with_name ( " " ) . takes_value ( true ) . required ( true ) . value_name ( " " ) . help ( " " ) ) . arg ( Arg :: with_name ( " " ) . short ( " " ) . help ( " " ) ) ; let cli_args = app . get_matches ( ) ; let verbose = cli_args . is_present ( " " ) ; let secondary = cli_args . value_of ( " " ) . unwrap_or ( " " ) ; let retries = if let Ok ( retries ) = cli_args . value_of ( " " ) . unwrap_or ( " " ) . parse :: < u16 > ( ) { retries } else { let msg = format ! ( " " cli_args value_of ( " " ) unwrap ( ) ) ; return Err ( ExitCodes :: InputError ( msg ) ) ; } ; let port = if let Ok ( port ) = cli_args . value_of ( " " ) . unwrap_or ( " " ) . parse :: < u16 > ( ) { port } else { let msg = format ! ( " " cli_args value_of ( " " ) unwrap ( ) ) ; return Err ( ExitCodes :: InputError ( msg ) ) ; } ; let record_type = if let Ok ( record_type ) = RecordType :: from_str ( cli_args . value_of ( " " ) . unwrap_or ( " " ) ) { record_type } else { let msg = format ! ( " " cli_args value_of ( " " ) unwrap ( ) ) ; return Err ( ExitCodes :: InputError ( msg ) ) ; } ; let domain_name = cli_args . value_of ( " " ) . unwrap ( ) ; Ok ( Config { retries : retries , secondary : secondary . to_string ( ) , port : port , record_type : record_type , domain_name : domain_name . to_string ( ) , verbose : verbose } ) }
Parses the command line parameters and creates a new `Config`.
Parses the command line parameters and creates a new ` Config ` .