Add init subcommand
This commit is contained in:
parent
43a958cdec
commit
900e1939f3
48
cmd/root.go
48
cmd/root.go
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
gVersion = "0.42a"
|
||||
gVersion = "0.42b"
|
||||
|
||||
// TODO : Get from $jail_zpool/defaults.json
|
||||
MIN_DYN_DEVFS_RULESET = 1000
|
||||
@ -59,6 +59,9 @@ var (
|
||||
|
||||
gTimeZone string
|
||||
gSnapshotName string
|
||||
gZPool string
|
||||
gBridge string
|
||||
gInterface string
|
||||
|
||||
gMigrateDestDatastore string
|
||||
gYesToAll bool
|
||||
@ -100,19 +103,13 @@ It support iocage jails and can coexist with iocage.`,
|
||||
},
|
||||
}
|
||||
|
||||
/* TODO
|
||||
Initialize datastore(s) /iocage, /iocage/jails
|
||||
Put defaults.json, update it with hostid,interfaces, and maybe other necessary fields
|
||||
Initialize bridge
|
||||
initCmd = &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Initialize GoCage",
|
||||
//Long: `Let this show you how much fail I had to get this *cough* perfect`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fv, _ := getFreeBSDVersion()
|
||||
fmt.Printf("GoCage v.%s on FreeBSD %d.%d-%s\n", gVersion, fv.major, fv.minor, fv.flavor)
|
||||
InitGoCage(args)
|
||||
},
|
||||
}*/
|
||||
}
|
||||
|
||||
listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
@ -395,6 +392,10 @@ func init() {
|
||||
rootCmd.PersistentFlags().BoolVar(&gDebug, "debug", false, "Debug mode")
|
||||
|
||||
// Command dependant switches
|
||||
initCmd.Flags().StringVarP(&gZPool, "pool", "p", "", "ZFS pool to create datastore on")
|
||||
initCmd.Flags().StringVarP(&gBridge, "bridge", "b", "", "bridge to create for jails networking")
|
||||
initCmd.Flags().StringVarP(&gInterface, "interface", "i", "", "interface to add as bridge member. This should be your main interface")
|
||||
initCmd.MarkFlagsRequiredTogether("bridge", "interface")
|
||||
|
||||
// We reuse these flags in "gocage snapshot list myjail" and 'gocage datastore list" commands
|
||||
listCmd.Flags().StringVarP(&gDisplayJColumns, "outcol", "o", "JID,Name,Config.Release,Config.Ip4_addr,Running", "Show these columns in output")
|
||||
@ -443,6 +444,7 @@ func init() {
|
||||
apiCmd.Flags().IntVarP(&gApiPort, "listen-port", "p", 1234, "API listening port")
|
||||
|
||||
// Now declare commands
|
||||
rootCmd.AddCommand(initCmd)
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
rootCmd.AddCommand(listCmd)
|
||||
listCmd.AddCommand(listPropsCmd)
|
||||
@ -461,7 +463,6 @@ func init() {
|
||||
rootCmd.AddCommand(upgradeCmd)
|
||||
rootCmd.AddCommand(createCmd)
|
||||
rootCmd.AddCommand(apiCmd)
|
||||
|
||||
rootCmd.AddCommand(testCmd)
|
||||
|
||||
snapshotCmd.AddCommand(snapshotListCmd)
|
||||
@ -492,17 +493,6 @@ func initConfig() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Load default configs from datastores
|
||||
err := ListDatastores(viper.GetStringSlice("datastore"), false)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: error checking datastores: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// fmt.Println("Using config file:", viper.ConfigFileUsed())
|
||||
// fmt.Printf("datastore in config : %s\n", viper.GetStringSlice("datastore"))
|
||||
// fmt.Printf("datastore.0 in config : %s\n", viper.GetStringSlice("datastore.0"))
|
||||
|
||||
// Command line flags have priority on config file
|
||||
if rootCmd.Flags().Lookup("sudo") != nil && false == rootCmd.Flags().Lookup("sudo").Changed {
|
||||
gUseSudo = viper.GetBool("sudo")
|
||||
@ -536,11 +526,25 @@ func initConfig() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
||||
if gDebug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.Debugf("Debug mode enabled\n")
|
||||
}
|
||||
|
||||
// no need to check prerequesites if we are initializing gocage
|
||||
for _, rc := range rootCmd.Commands() {
|
||||
//fmt.Printf("DEBUG: rootCmd subcommand: %v. Was it called? %s\n", rc.Use, rootCmd.Commands()[i].CalledAs())
|
||||
if len(rc.CalledAs()) > 0 && strings.EqualFold("init", rc.CalledAs()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Load default configs from datastores
|
||||
err := ListDatastores(viper.GetStringSlice("datastore"), false)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: error checking datastores: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user