To add a new command, you must define it using the urfave/cli package and register it with the github.com/smallstep/cli/command package. This allows the command to be available in the cmd/step/main.go entrypoint.
- Define and Register: Create a new package for your command. In the
init() function, define a cli.Command struct and call command.Register(). - Import for Registration: For top-level commands, you must add a blank import of your command package in
cmd/step/main.go to ensure the init() function executes.
package validate
import (
"github.com/urfave/cli"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/flags"
)
func init() {
cmd := cli.Command{
Name: "validate",
Usage: "Returns whether or not the provided token is valid",
Flags: []cli.Flag{
flags.Token("The one-time token value to validate"),
},
Action: validate,
}
command.Register(validate)
}
In cmd/step/main.go:
package main
import (
"github.com/urfave/cli"
_ "github.com/smallstep/cli/validate"
)