Skip to content

Commit

Permalink
Merge pull request #55 from ksk001100/feature/fix-v1.1.0
Browse files Browse the repository at this point in the history
Show command alias in help
  • Loading branch information
ksk001100 authored Oct 31, 2020
2 parents 8963ae3 + 06943b1 commit d69ed6b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "seahorse"
version = "1.1.0"
version = "1.1.1"
authors = ["ksk001100 <[email protected]>"]
edition = "2018"
keywords = [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To use seahorse, add this to your Cargo.toml:

```toml
[dependencies]
seahorse = "1.1.0"
seahorse = "1.1"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn hello_command() -> Command {
Command::new("hello")
.description("hello command")
.usage("multiple_app hello(he, h) [name]")
.alias("he")
.alias("h")
.alias("he")
.action(hello_action)
.flag(
Flag::new("bye", FlagType::Bool)
Expand Down
22 changes: 18 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,24 @@ impl App {
if let Some(commands) = &self.commands {
text += "\nCommands:\n";

let name_max_len = &commands.iter().map(|c| c.name.len()).max().unwrap();
let name_max_len = &commands
.iter()
.map(|c| {
if let Some(alias) = &c.alias {
format!("{}, {}", alias.join(", "), c.name).len()
} else {
c.name.len()
}
})
.max()
.unwrap();

for c in commands {
let command_name_len = c.name.len();
let command_name = if let Some(alias) = &c.alias {
format!("{}, {}", alias.join(", "), c.name)
} else {
c.name.clone()
};

let description = match &c.description {
Some(description) => description,
Expand All @@ -345,8 +359,8 @@ impl App {

text += &format!(
"\t{} {}: {}\n",
c.name,
" ".repeat(name_max_len - command_name_len),
command_name,
" ".repeat(name_max_len - command_name.len()),
description
);
}
Expand Down

0 comments on commit d69ed6b

Please sign in to comment.