clap_flags

crates.io version build status downloads docs.rs docs

Collection of reusable flags for Clap.

Usage

```rust use futures::prelude::*; use hyper::service::servicefnok; use hyper::{Body, Response, Server}; use structopt::StructOpt;

[derive(Debug, StructOpt)]

struct Cli { #[structopt(flatten)] verbosity: clapflags::Verbosity, #[structopt(flatten)] logger: clapflags::Log, #[structopt(flatten)] port: clap_flags::Port, }

fn main() -> Result<(), Box> { let args = Cli::from_args(); let listener = args.port.bind()?;

args.logger.logall(args.verbosity.loglevel())?;

let handle = tokio::reactor::Handle::current(); let listener = tokio::net::TcpListener::fromstd(listener, &handle)?; let addr = listener.localaddr()?;

let server = Server::builder(listener.incoming()) .serve(|| servicefnok(|| Response::new(Body::from("Hello World")))) .maperr(|e| eprintln!("server error: {}", e));

info!("Server listening on {}", addr); tokio::run(server);

Ok(()) } ```

Output

```txt clap_flags 0.1.0 Yoshua Wuyts yoshuawuyts@gmail.com Collection of reusable flags for Clap

USAGE: main [FLAGS] [OPTIONS]

FLAGS: -h, --help Prints help information -P, --pretty Enable pretty printing. -V, --version Prints version information -v, --verbosity Pass many times for more log output

OPTIONS: -a, --address

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

Installation

sh $ cargo add clap_flags

License

MIT OR Apache-2.0