package cmd import ( "fmt" "os" "github.com/spf13/cobra" "github.com/warkanum/unitdore/config" "github.com/warkanum/unitdore/sysuser" ) var version = "1.0.0" var configPath string var rootCmd = &cobra.Command{ Use: "unitdore", Short: "A door you open and close for container units", Long: `Unitdore manages container units via the system init (systemd, OpenRC or runit). It discovers running containers and podman-compose stacks, stores them in a config file, and generates + manages init service units for each one (systemd by default; set 'init:' in the config for openrc or runit). As root: system units, plus user units for users listed in 'users:'. As a normal user: own config and user units only.`, Version: version, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { // Normal users get their own config and manage only their user units if !cmd.Flags().Changed("config") && !sysuser.IsRoot() { home, err := sysuser.HomeDir(sysuser.Current()) if err != nil { return err } configPath = config.UserConfigPath(home) } return nil }, } func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } func init() { rootCmd.PersistentFlags().StringVar(&configPath, "config", config.DefaultConfigPath, "path to units config file (default for non-root: ~/.config/unitdore/units.yaml)") }