Skip to content

Commit

Permalink
feat: description also for root command
Browse files Browse the repository at this point in the history
  • Loading branch information
Zdenko Vrabel committed May 10, 2022
1 parent f8e66b9 commit eb8297c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ But for easy to use you should move the `toolbx` binary somewhere in your `PATH`

When you installed `toolbx` binary, as second step is configuration of your
command repository. It's repository where are all commands and subcommands
defined. You can use `toolbx-demo` repository.
defined. You can use `toolbx-demo` repository:

```
echo "repository: https://github.com/sn3d/toolbx-demo.git" > ~/.toolbx.yaml
$ echo "repository: https://github.com/sn3d/toolbx-demo.git" > ~/.toolbx.yaml
```

Now you can start using `toolbx`. If you run subcommand `toolbx storage`, you
should be synchronized with command repository, and you should get
the list of all `storage` subcommands.
```
$ toolbx storage
```
2 changes: 1 addition & 1 deletion repo_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (repo *CommandsRepository) GetCommand(args []string) (*api.Command, error)

subCmd, err := getSubCommand(rootCmd, args)
if errors.Is(err, NoChildError) {
return rootCmd, nil
subCmd = rootCmd
}

err = loadMetadata(subCmd)
Expand Down
18 changes: 14 additions & 4 deletions toolbx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ type Toolbx struct {

func Main(options ...ToolbxOption) error {
tlbx, err := Create(options...)
if err != nil {
log.Fatalln("error starting toolbx", err)
if err == MissingRepoError {
fmt.Println("Hello, and welcome!")
fmt.Println("")
fmt.Println("Do one simple configuration step before you start using Toolbx:")
fmt.Println("")
fmt.Println(" echo \"repository: https://github.com/sn3d/toolbx-demo.git\" > ~/.toolbx.yaml")
fmt.Println("")
return nil
} else if err != nil {
log.Fatalln("error starting toolbx:", err)
}

err = tlbx.Execute(os.Args)
if err != nil {
log.Fatalln("error executing command", err)
log.Fatalln("error executing command:", err)
}

return nil
Expand Down Expand Up @@ -96,9 +104,11 @@ func (t *Toolbx) Execute(args []string) error {
}

if len(cmd.Args) > 0 {
fmt.Printf("Unknown sub-command '%s' in %v\n", cmd.Args[0], cmd.Args)
fmt.Printf("Unknown sub-command '%s'\n", cmd.Args[0])
}

fmt.Printf("\n%s\n", cmd.Metadata.Description)

d := color.New(color.FgHiWhite, color.Bold)
d.Printf("\nAvailable sub-commands for %s\n\n", name)

Expand Down

0 comments on commit eb8297c

Please sign in to comment.