chose listed jails, show real field name in header, sudo parameter, moved utilities into cmd/utils.go, started working on stop command
This commit is contained in:
30
cmd/root.go
30
cmd/root.go
@ -14,6 +14,10 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
gJails []Jail
|
||||
|
||||
gUseSudo bool
|
||||
|
||||
gConfigFile string
|
||||
|
||||
rootCmd = & cobra.Command{
|
||||
@ -39,9 +43,22 @@ It support iocage jails and can coexist with iocage.`,
|
||||
listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "Print jails",
|
||||
Long: `Display jails, their IP and OS`,
|
||||
Long: `Display jails, their IP and OS.
|
||||
Jail list can be restricted by adding name on command line
|
||||
ex: gocage list srv-db srv-web`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
listJails(args)
|
||||
listJails(args, true)
|
||||
},
|
||||
}
|
||||
|
||||
stopCmd = &cobra.Command{
|
||||
Use: "stop",
|
||||
Short: "stop jail",
|
||||
Long: `shutdown jail`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Get the inventory
|
||||
listJails(args, false)
|
||||
stopJail(args)
|
||||
},
|
||||
}
|
||||
)
|
||||
@ -52,7 +69,8 @@ func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
|
||||
// Global switches
|
||||
rootCmd.PersistentFlags().StringVarP(&gConfigFile, "config", "c", "/etc/gocage/gocage.conf", "GoCage configuration file")
|
||||
rootCmd.PersistentFlags().StringVarP(&gConfigFile, "config", "c", "/usr/local/etc/gocage.conf.yml", "GoCage configuration file")
|
||||
rootCmd.PersistentFlags().BoolVarP(&gUseSudo, "sudo", "s", false, "Use sudo to run commands")
|
||||
|
||||
// Command dependant switches
|
||||
/* listComputerCmd.PersistentFlags().BoolVarP(&gDisplayAsCSV, "csv-format", "v", false, "Show results in CSV (separator = ';')")
|
||||
@ -63,12 +81,13 @@ func init() {
|
||||
// Now declare commands
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
rootCmd.AddCommand(listCmd)
|
||||
rootCmd.AddCommand(stopCmd)
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
if gConfigFile == "" {
|
||||
fmt.Println("No config file!")
|
||||
return
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// fmt.Printf("We are in initConfig(), with config file %s\n", gConfigFile)
|
||||
@ -77,12 +96,13 @@ func initConfig() {
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
fmt.Printf("ERROR reading config file %s : %s\n", gConfigFile, err.Error())
|
||||
return
|
||||
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"))
|
||||
gUseSudo = viper.GetBool("sudo")
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
|
||||
Reference in New Issue
Block a user