clap-port-flag 0.3.0

Easily add a --port flag to CLIs using Structopt.
Documentation

clap-port-flag

crates.io version build status downloads docs.rs docs

Easily add a --port flag to CLIs using Structopt.

Usage

With the following code in src/main.rs:

extern crate clap_port_flag;
#[macro_use] extern crate structopt;

use structopt::StructOpt;
use clap_port_flag::Port;

#[derive(Debug, StructOpt)]
struct Cli {
  #[structopt(flatten)]
  port: Port,
}

fn main() {
  let args = Cli::from_args();
  let _tcp_listener = args.port.bind().unwrap();
}

When you run the binary, it'll provide the following output:

my-cool-app 0.2.0
Alice Person <alice@person.com>
Application that does things over TCP.

USAGE:
    main [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --listen-fd <fd>         A previously opened network socket. [env: LISTEN_FD=]
    -a, --address <hostname>     The network address to listen to. [default: 127.0.0.1]
    -p, --port <port>            The network port to listen to. [env: PORT=]

Installation

$ cargo add clap-port-flag

Further Reading

Acknowledgements

The original version of this crate was sketched out by @TeXitoi in rust-lang-nursery/cli-wg#37.

License

MIT OR Apache-2.0