Skip to content

Commit

Permalink
Feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed Feb 22, 2024
1 parent 5e1d905 commit 8ef67cf
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/help-generator_.toit
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,9 @@ class HelpGenerator:
// commands that defined them.
full-command := []
is-root := true
// For examples we don't want the full path that was used to invoke the
// For examples, we don't want the full path that was used to invoke the
// command (like `build/bin/artemis`), but only the basename.
app-name := invoked-command_
separator-index := app-name.index-of --last "/"
if system.platform == system.PLATFORM-WINDOWS:
separator-index = max separator-index (app-name.index-of --last "\\")
app-name = app-name[separator-index + 1..]

app-name := basename_ invoked-command_
parsed-path.do: | current-command |
if is-root:
is-root = false
Expand All @@ -554,6 +549,18 @@ class HelpGenerator:

writeln_ (full-command.join " ") --indentation=2

/**
Extracts the basename of a path.
This is a simplified version that doesn't take into account volume names or
other complications.
*/
basename_ path/string -> string:
separator-index := path.index-of --last "/"
if system.platform == system.PLATFORM-WINDOWS:
separator-index = max separator-index (path.index-of --last "\\")
return path[separator-index + 1..]

/**
Splits a string into individual arguments.
*/
Expand Down

0 comments on commit 8ef67cf

Please sign in to comment.