Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Man gen #6

Merged
merged 12 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate that you don't put empty lines around code blocks. Just so you know. :P

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing; your comment has been noted 😛

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a side note: I'll happily switch to whichever style is conventional the moment rustfmt is able to do so automatically. Can't be bothered to otherwise :P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brb, doing cargo new mdfmt

```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("alice@person.com".into()))
.author("Bob Human", Some("bob@human.com".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::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only expose some very carefully selected items.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we can get #9 to land, this will also be solved. For now it mostly enforces the same behavior we'd have as putting everything in lib/ (e.g. less typing until we clean things up, haha).


/// 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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably also derive Clone. Not necessary right now but you're not using Debug, too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

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)]
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)]
pub struct Flag {
pub(crate) short: Option<String>,
pub(crate) long: Option<String>,
pub(crate) description: Option<String>,
}
Loading