Skip to content

Commit

Permalink
update CONTRIBUTING.md
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Mar 13, 2024
1 parent 506b0b3 commit 65a904c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,25 @@ Additional Commands:
set-rdns Change reverse DNS of a Server
ssh Spawn an SSH connection for the server
```

### Command validation

Please use the `util.Validate` method to make sure the command is validated against its usage string during runtime.
This can be done by setting the `Args` field of the `cobra.Command` struct to `util.Validate`:

```go
cmd := &cobra.Command{
Use: "my-command [options]",
Args: util.Validate,
Run: func(cmd *cobra.Command, args []string) {
// ...
},
}
```

If you are using base commands like `base.Cmd` or `base.ListCmd` etc., this is already done for you.

**Note:** Your command usage needs to follow the [docopt](http://docopt.org/) syntax for this to work.
If your command uses optional positional arguments or other complicated usage that necessitates to disable
argument count checking, you use `util.ValidateLenient` instead. It will not throw an error if there are
more arguments than expected.

0 comments on commit 65a904c

Please sign in to comment.