airshipctl/cmd/root.go
Ian Howell 039224b6fe Move kubernetes configuration into settings
This should make it easier to use the fake client for testing
2019-05-21 12:43:03 -05:00

56 lines
1.3 KiB
Go

package cmd
import (
"fmt"
"io"
"os"
"github.com/spf13/cobra"
"github.com/ian-howell/airshipctl/pkg/environment"
"github.com/ian-howell/airshipctl/pkg/log"
)
// NewRootCmd creates the root `airshipctl` command. All other commands are
// subcommands branching from this one
func NewRootCmd(out io.Writer, settings *environment.AirshipCTLSettings, args []string) (*cobra.Command, error) {
rootCmd := &cobra.Command{
Use: "airshipctl",
Short: "airshipctl is a unified entrypoint to various airship components",
}
rootCmd.SetOutput(out)
settings.InitFlags(rootCmd)
rootCmd.AddCommand(NewVersionCommand(out))
loadPluginCommands(rootCmd, out, settings, args)
rootCmd.PersistentFlags().Parse(args)
settings.InitDefaults()
log.Init(settings, out)
return rootCmd, nil
}
// Execute runs the base airshipctl command
func Execute(out io.Writer) {
rootCmd, err := NewRootCmd(out, &environment.AirshipCTLSettings{}, os.Args[1:])
if err != nil {
fmt.Fprintln(out, err)
os.Exit(1)
}
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(out, err)
os.Exit(1)
}
}
// loadPluginCommands loads all of the plugins as subcommands to cmd
func loadPluginCommands(cmd *cobra.Command, out io.Writer, settings *environment.AirshipCTLSettings, args []string) {
for _, subcmd := range pluginCommands {
cmd.AddCommand(subcmd(out, settings, args))
}
}