-
Notifications
You must be signed in to change notification settings - Fork 9
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
Revise exit status section #30
Open
codesections
wants to merge
8
commits into
rust-cli:master
Choose a base branch
from
codesections-forks:exit-status
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0c639db
Revise exit status section
codesections 9e9598c
Merge branch 'master' into exit-status
codesections a09fcd7
Minor changes for readability
codesections 68c2578
Refactor to avoid sentential value
codesections d97d93a
Change `match` statement to `if let` statement
codesections 71444fc
Add an iter method to the ExitStatuses enum
codesections 272a413
Clippy lints
codesections 4be6860
Revert removal of Option wrapping `code`
codesections File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 |
---|---|---|
|
@@ -31,6 +31,7 @@ fn main() { | |
.long("--port") | ||
.help("The network port to listen to."), | ||
) | ||
.exit_status(ExitStatus::default()) | ||
.example( | ||
Example::new() | ||
.text("listen on port 3000") | ||
|
@@ -43,11 +44,6 @@ fn main() { | |
.prompt("#") | ||
.command("auth-service"), | ||
) | ||
.custom( | ||
Section::new("custom section") | ||
.paragraph("text for the custom section") | ||
.paragraph("Additional text for the custom section"), | ||
) | ||
.author(Author::new("Alice Person").email("[email protected]")) | ||
.author(Author::new("Bob Human").email("[email protected]")) | ||
.render(); | ||
|
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,61 @@ | ||
extern crate man; | ||
|
||
use man::prelude::*; | ||
|
||
fn main() { | ||
let msg = Manual::new("auth-service") | ||
.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."), | ||
) | ||
.custom( | ||
Section::new("custom section") | ||
.paragraph("text for the custom section") | ||
.paragraph("Additional text for the custom section"), | ||
) | ||
.custom( | ||
Section::new("second custom section") | ||
.paragraph("text for the custom section") | ||
.paragraph("Additional text for the custom section"), | ||
) | ||
.exit_status(ExitStatus::new(0)) | ||
.example( | ||
Example::new() | ||
.text("listen on port 3000") | ||
.command("auth-service -p 3000") | ||
.output("now listening on port 3000"), | ||
) | ||
.example( | ||
Example::new() | ||
.text("auth-service may need to be run by root") | ||
.prompt("#") | ||
.command("auth-service"), | ||
) | ||
.author(Author::new("Alice Person").email("[email protected]")) | ||
.author(Author::new("Bob Human").email("[email protected]")) | ||
.render(); | ||
|
||
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,20 @@ | ||
/// Add a exit status section | ||
#[derive(Debug, Clone, Default)] | ||
pub struct ExitStatus { | ||
pub(crate) code: Option<i32>, | ||
pub(crate) description: Option<&'static str>, | ||
} | ||
|
||
impl ExitStatus { | ||
pub fn new(code: i32) -> Self { | ||
Self { | ||
code: Some(code), | ||
description: None, | ||
} | ||
} | ||
|
||
pub fn description(mut self, description: &'static str) -> Self { | ||
self.description = Some(description); | ||
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
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 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so this line is what I was missing! I didn't get when you would ever set the exit status list to the default list – I assumed it was the set you were starting with and then when you add a custom one it gets overwritten.
This behavior here is surprising to me: When you call this public function, that has no docs, with a "special" value (
code = None
), it does an unusual thing. What's also weird: To get this special input you'd have to calldefault()
, but from what I can tell this "special" mode should not be the "default".