Skip to content

Commit

Permalink
refactor: auto-aliasing subcmds (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Dec 1, 2024
1 parent 59ae229 commit 3bec9ce
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,11 @@ impl Command {

// auto alias if command name contains `_`
if let Some(name) = self.name.clone() {
let compatible_name = name
.chars()
.enumerate()
.map(|(i, c)| if i > 0 && c == '_' { '-' } else { c })
.collect::<String>();
let compatible_name = if !name.starts_with('_') {
name.replace("_", "-")
} else {
name.clone()
};
if compatible_name != name {
match self.aliases.as_mut() {
Some((aliaes, _)) => aliaes.insert(0, compatible_name),
Expand Down

0 comments on commit 3bec9ce

Please sign in to comment.