Skip to content

Commit

Permalink
Man gen (#6)
Browse files Browse the repository at this point in the history
* init man generator

* authors works!

* clean up author list

* slightly better examples

* chaining API

* exit status

* flags

* brush up example

* options

* add arguments

* environment

* derive clone
  • Loading branch information
yoshuawuyts authored Jul 24, 2018
1 parent fc11e37 commit a6271b8
Show file tree
Hide file tree
Showing 10 changed files with 460 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ readme = "README.md"

[dependencies]
clap = { git = "https://github.com/kbknapp/clap-rs", branch = "v3-dev" }
roff = "0.1.0"

[dev-dependencies]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ fn main() {
.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");

let _string = page.to_string();
}
```
Preview by running:
```sh
$ cargo run > /tmp/app.man; man /tmp/app.man
```

## Installation
```sh
Expand Down
49 changes: 49 additions & 0 deletions examples/demo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
extern crate man;

use man::Man;

fn main() {
let msg = Man::new("auth-service")
.description("authorize & authenticate members")
.argument("path".into())
.environment(
"PORT".into(),
None,
Some("The network port to listen to.".into()),
)
.flag(
Some("-h".into()),
Some("--help".into()),
Some("Prints help information.".into()),
)
.flag(
Some("-V".into()),
Some("--version".into()),
Some("Prints version information.".into()),
)
.flag(
Some("-v".into()),
Some("--verbosity".into()),
Some("Pass multiple times to print more information.".into()),
)
.option(
Some("-a".into()),
Some("--address".into()),
Some("The network address to listen to.".into()),
"address".into(),
Some("127.0.0.1".into()),
)
.option(
Some("-p".into()),
Some("--port".into()),
Some("The network port to listen to.".into()),
"port".into(),
None,
)
.author("Alice Person", Some("[email protected]".into()))
.author("Bob Human", Some("[email protected]".into()))
.render();
// .option(Some("-o"), Some("--output"), "output", None, "Output file");

println!("{}", msg);
}
2 changes: 1 addition & 1 deletion examples/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate clap;
extern crate man;

use clap::{App, AppSettings, Arg, SubCommand};
use clap::{App, AppSettings, Arg, Man, SubCommand};
use man::Manual;

fn main() {
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
#![cfg_attr(test, deny(warnings))]

extern crate clap;
extern crate roff;

mod man;

use clap::{App, Arg, ArgSettings};
pub use man::*;

/// Describe an argument or option
#[derive(Debug)]
Expand Down
6 changes: 6 additions & 0 deletions src/man/author.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// An author entry.
#[derive(Debug, Clone)]
pub struct Author {
pub(crate) name: String,
pub(crate) email: Option<String>,
}
7 changes: 7 additions & 0 deletions src/man/environment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// Command line environment variable representation.
#[derive(Debug, Clone)]
pub struct Env {
pub(crate) name: String,
pub(crate) default: Option<String>,
pub(crate) description: Option<String>,
}
7 changes: 7 additions & 0 deletions src/man/flag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// Command line flag representation.
#[derive(Debug, Clone)]
pub struct Flag {
pub(crate) short: Option<String>,
pub(crate) long: Option<String>,
pub(crate) description: Option<String>,
}
Loading

0 comments on commit a6271b8

Please sign in to comment.