diff --git a/cmd/root.go b/cmd/root.go index 2a38156..890992b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -30,23 +30,22 @@ var ( rootCmd = & cobra.Command{ - Use: "gocage", - Short: "GoCage is a FreeBSD Jail management tool", - Long: `GoCage is a jail management tool. It support VNET, host-only, NAT networks. Provides snapshots and cloning. + Use: "gocage", + Short: "GoCage is a FreeBSD Jail management tool", + Long: `GoCage is a jail management tool. It support VNET, host-only, NAT networks. Provides snapshots and cloning. It support iocage jails and can coexist with iocage.`, - - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Here we are in the Run") + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("Here we are in the Run") cleanAfterRun() - }, + }, } - + versionCmd = &cobra.Command{ - Use: "version", - Short: "Print the version number of GoCage", - Long: `Let this show you how much fail I had to get this *cough* perfect`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("GoCage v.%s on FreeBSD %.1f\n", gVersion, gHostVersion) + Use: "version", + Short: "Print the version number of GoCage", + Long: `Let this show you how much fail I had to get this *cough* perfect`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("GoCage v.%s on FreeBSD %.1f\n", gVersion, gHostVersion) cleanAfterRun() }, } @@ -95,6 +94,19 @@ ex: gocage list srv-db srv-web`, cleanAfterRun() }, } + + setCmd = &cobra.Command{ + Use: "set", + Short: "Set a jail property", + Long: `Set jail property value. Specify property=value, end command with jail name. +Multiples properties can be specified, separated with space (Ex: gocage set allow_mlock=1 boot=1 myjail)`, + Run: func(cmd *cobra.Command, args []string) { + // Get the inventory + ListJails(args, false) + SetJailProperties(args) + cleanAfterRun() + }, + } ) @@ -103,21 +115,22 @@ func init() { cobra.OnInitialize(initConfig) // Global switches - rootCmd.PersistentFlags().StringVarP(&gConfigFile, "config", "c", "/usr/local/etc/gocage.conf.yml", "GoCage configuration file") - rootCmd.PersistentFlags().BoolVarP(&gUseSudo, "sudo", "u", false, "Use sudo to run commands") + rootCmd.PersistentFlags().StringVarP(&gConfigFile, "config", "c", "/usr/local/etc/gocage.conf.yml", "GoCage configuration file") + rootCmd.PersistentFlags().BoolVarP(&gUseSudo, "sudo", "u", false, "Use sudo to run commands") // Command dependant switches - listCmd.PersistentFlags().StringVarP(&gDisplayColumns, "outcol", "o", "JID,Name,Config.Release,Config.Ip4_addr,Running", "Show these columns in output") - listCmd.PersistentFlags().BoolVarP(&gNoLineSep, "nolinesep", "l", false, "Do not display line separator between jails") - listCmd.PersistentFlags().StringVarP(&gFilterJails, "filter", "f", "none", "Only display jails with these values. Ex: \"gocage list -f Config.Boot=1\" will only list started on boot jails") - listCmd.PersistentFlags().StringVarP(&gSortFields, "sort", "s", "none", "Display jails sorted by field values. Ex: \"gocage list -s +Name,-Config.Priority\" will sort jails by their decreasing name, then increasing start priority. 3 critera max supported.") + listCmd.PersistentFlags().StringVarP(&gDisplayColumns, "outcol", "o", "JID,Name,Config.Release,Config.Ip4_addr,Running", "Show these columns in output") + listCmd.PersistentFlags().BoolVarP(&gNoLineSep, "nolinesep", "l", false, "Do not display line separator between jails") + listCmd.PersistentFlags().StringVarP(&gFilterJails, "filter", "f", "none", "Only display jails with these values. Ex: \"gocage list -f Config.Boot=1\" will only list started on boot jails") + listCmd.PersistentFlags().StringVarP(&gSortFields, "sort", "s", "none", "Display jails sorted by field values. Ex: \"gocage list -s +Name,-Config.Priority\" will sort jails by their decreasing name, then increasing start priority. 3 critera max supported.") // Now declare commands - rootCmd.AddCommand(versionCmd) - rootCmd.AddCommand(listCmd) + rootCmd.AddCommand(versionCmd) + rootCmd.AddCommand(listCmd) listCmd.AddCommand(listPropsCmd) - rootCmd.AddCommand(stopCmd) - rootCmd.AddCommand(startCmd) + rootCmd.AddCommand(stopCmd) + rootCmd.AddCommand(startCmd) + rootCmd.AddCommand(setCmd) // Get FreeBSD version out, err := executeCommand("freebsd-version") @@ -126,7 +139,7 @@ func init() { os.Exit(1) } gHostVersion, _ = strconv.ParseFloat(strings.Split(out, "-")[0], 32) - + } func initConfig() { @@ -186,10 +199,10 @@ func cleanAfterRun() { } func Execute() { - if err := rootCmd.Execute(); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } + if err := rootCmd.Execute(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } }