-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove all clap-related code * builder pattern all the way through * port example to builder pattern * update readme * s/description/help/g * arg struct * s/Man/Manual/ * more exit codes
- Loading branch information
1 parent
a6271b8
commit 16b74df
Showing
16 changed files
with
561 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,40 @@ | ||
extern crate clap; | ||
extern crate man; | ||
|
||
use clap::{App, AppSettings, Arg, Man, SubCommand}; | ||
use man::Manual; | ||
use man::prelude::*; | ||
|
||
fn main() { | ||
let a = App::new("testapp") | ||
.about("Pointless application") | ||
.setting(AppSettings::SubcommandRequiredElseHelp) | ||
.author("Katharina Fey <[email protected]>") | ||
// .author("Yosh Wuyts <[email protected]") | ||
.long_about("Lorem Ipsum bla bla bla") | ||
.arg(Arg::with_name("debug").short("d").help("Make program output debug messages")) | ||
.arg(Arg::with_name("output").short("o").takes_value(true).help("Output File")) | ||
.subcommand(SubCommand::with_name("foo").arg(Arg::with_name("bar").short("b").long("barr"))); | ||
let msg = Manual::new("auth-service") | ||
.about("authorize & authenticate members".into()) | ||
.arg(Arg::new("path")) | ||
.env(Env::new("PORT").help("The network port to listen to")) | ||
.flag( | ||
Flag::new() | ||
.short("-h") | ||
.long("--help") | ||
.help("Prints help information."), | ||
) | ||
.flag( | ||
Flag::new() | ||
.short("-V") | ||
.long("--version") | ||
.help("Prints version information."), | ||
) | ||
.flag( | ||
Flag::new() | ||
.short("-v") | ||
.long("--verbosity") | ||
.help("Pass multiple times to print more information."), | ||
) | ||
.option( | ||
Opt::new("port") | ||
.short("-p") | ||
.long("--port") | ||
.help("The network port to listen to."), | ||
) | ||
.author(Author::new("Alice Person").email("[email protected]")) | ||
.author(Author::new("Bob Human").email("[email protected]")) | ||
.render(); | ||
// .option(Some("-o"), Some("--output"), "output", None, "Output file"); | ||
|
||
let manual = Manual::from_clap(&a); | ||
println!("{:#?}", manual); | ||
|
||
// let page = Man::new("basic") | ||
// .description("A basic example") | ||
// .author("Alice", Some("[email protected]")) | ||
// .author("Bob", Some("[email protected]")) | ||
// .flag(Some("-d"), Some("--debug"), Some("Activate debug mode")) | ||
// .flag(Some("-v"), Some("--verbose"), Some("Verbose mode")); | ||
// .option(Some("-o"), Some("--output"), "output", None, "Output file"); | ||
println!("{}", msg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#[derive(Debug, Clone)] | ||
pub struct Arg { | ||
pub(crate) name: String, | ||
} | ||
|
||
impl Arg { | ||
pub fn new(name: &str) -> Self { | ||
Self { name: name.into() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/// An author entry. | ||
#[derive(Debug, Clone)] | ||
pub struct Author { | ||
pub(crate) name: String, | ||
pub(crate) email: Option<String>, | ||
} | ||
|
||
impl Author { | ||
/// Create a new instance. | ||
pub fn new(name: &str) -> Self { | ||
Self { | ||
name: name.into(), | ||
email: None, | ||
} | ||
} | ||
|
||
/// Set the email field. | ||
pub fn email(mut self, email: &str) -> Self { | ||
self.email = Some(email.into()); | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// Command line environment variable representation. | ||
#[derive(Debug, Clone)] | ||
pub struct Env { | ||
pub(crate) name: String, | ||
pub(crate) default: Option<String>, | ||
pub(crate) help: Option<String>, | ||
} | ||
|
||
impl Env { | ||
/// Create a new instance. | ||
pub fn new(name: &str) -> Self { | ||
Self { | ||
name: name.into(), | ||
default: None, | ||
help: None, | ||
} | ||
} | ||
|
||
/// Set the default value. | ||
pub fn default_value(mut self, default: &str) -> Self { | ||
self.default = Some(default.into()); | ||
self | ||
} | ||
|
||
/// Set the help. | ||
pub fn help(mut self, help: &str) -> Self { | ||
self.help = Some(help.into()); | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// Command line flag representation. | ||
#[derive(Debug, Clone)] | ||
pub struct Flag { | ||
pub(crate) short: Option<String>, | ||
pub(crate) long: Option<String>, | ||
pub(crate) help: Option<String>, | ||
} | ||
|
||
impl Flag { | ||
/// Create a new instance. | ||
pub fn new() -> Self { | ||
Self { | ||
short: None, | ||
long: None, | ||
help: None, | ||
} | ||
} | ||
|
||
/// Set the short value. | ||
pub fn short(mut self, short: &str) -> Self { | ||
self.short = Some(short.into()); | ||
self | ||
} | ||
|
||
/// Set the long value. | ||
pub fn long(mut self, long: &str) -> Self { | ||
self.long = Some(long.into()); | ||
self | ||
} | ||
|
||
/// Set the help value. | ||
pub fn help(mut self, help: &str) -> Self { | ||
self.help = Some(help.into()); | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.