Add a convenience NewAirshipCTLCommand function
This adds the NewAirshipCTLCommand, a function which returns the root airshipctl command with all of the default plugins preloaded
This commit is contained in:
@@ -11,6 +11,12 @@ import (
|
|||||||
"github.com/ian-howell/airshipctl/pkg/log"
|
"github.com/ian-howell/airshipctl/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewAirshipCTLCommand creates a root `airshipctl` command with the default commands attached
|
||||||
|
func NewAirshipCTLCommand(out io.Writer) (*cobra.Command, *environment.AirshipCTLSettings, error) {
|
||||||
|
rootCmd, settings, err := NewRootCmd(out)
|
||||||
|
return AddDefaultAirshipCTLCommands(rootCmd, settings), settings, err
|
||||||
|
}
|
||||||
|
|
||||||
// NewRootCmd creates the root `airshipctl` command. All other commands are
|
// NewRootCmd creates the root `airshipctl` command. All other commands are
|
||||||
// subcommands branching from this one
|
// subcommands branching from this one
|
||||||
func NewRootCmd(out io.Writer) (*cobra.Command, *environment.AirshipCTLSettings, error) {
|
func NewRootCmd(out io.Writer) (*cobra.Command, *environment.AirshipCTLSettings, error) {
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -8,14 +8,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rootCmd, settings, err := cmd.NewRootCmd(os.Stdout)
|
rootCmd, _, err := cmd.NewAirshipCTLCommand(os.Stdout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stdout, err)
|
fmt.Fprintln(os.Stdout, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.AddDefaultAirshipCTLCommands(rootCmd, settings)
|
|
||||||
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
fmt.Fprintln(os.Stdout, err)
|
fmt.Fprintln(os.Stdout, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user