Attribute Macro merge_opt

Source
#[merge_opt]
Expand description

This attribute macro merges the command-line arguments from all structs identified as field of the current struct. The result will implement structopt::StructOpt and Debug automatically. All field types are required to implement structopt::StructOpt and Debug.

use pingora_core::server::configuration::Opt as ServerOpt;
use module_utils::merge_opt;
use static_files_module::StaticFilesOpt;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct MyAppOpt {
    /// IP address and port for the server to listen on
    #[structopt(long, default_value = "127.0.0.1:8080")]
    listen: String,
}

/// Starts my great application.
///
/// Additional application description just to make a structopt bug work-around work.
#[merge_opt]
struct Opt {
    app: MyAppOpt,
    server: ServerOpt,
    static_files: StaticFilesOpt,
}

let opt = Opt::from_args();
println!("Application options: {:?}", opt.app);
println!("Pingora server options: {:?}", opt.server);
println!("Static files options: {:?}", opt.static_files);