package cmd import ( "fmt" "github.com/spf13/cobra" "github.com/warkanum/unitdore/config" "github.com/warkanum/unitdore/systemd" ) var stopCmd = &cobra.Command{ Use: "stop ", Short: "Stop a unit by name", Args: cobra.ExactArgs(1), RunE: runStop, } func init() { rootCmd.AddCommand(stopCmd) } func runStop(cmd *cobra.Command, args []string) error { cfg, err := config.Load(configPath) if err != nil { return err } name := args[0] u := cfg.FindUnit(name) if u == nil { return fmt.Errorf("unit %q not found", name) } prefix, suffix := cfg.Prefix, cfg.Suffix if !systemd.IsInstalled(*u, prefix, suffix) { return fmt.Errorf("%s is not installed", name) } fmt.Printf(" ■ stopping %s...\n", systemd.ServiceName(*u, prefix, suffix)) if err := systemd.Stop(*u, prefix, suffix); err != nil { return err } fmt.Printf(" ✓ stopped: %s\n", name) return nil }