77 "os"
88 "os/exec"
99
10- "github.com/function61/gokit/app/cli"
1110 "github.com/function61/gokit/os/systemdinstaller"
1211 "github.com/spf13/cobra"
1312)
@@ -39,34 +38,34 @@ func Entrypoint(serviceName string, makeAdditionalCommands func(string) []*cobra
3938 Use : "start" ,
4039 Short : "Start the service" ,
4140 Args : cobra .NoArgs ,
42- Run : cli . WrapRun ( func (ctx context. Context , _ []string ) error {
43- return runSystemctlVerb (ctx , "start" )
44- }) ,
41+ RunE : func (cmd * cobra. Command , _ []string ) error {
42+ return runSystemctlVerb (cmd . Context () , "start" )
43+ },
4544 })
4645
4746 cmd .AddCommand (& cobra.Command {
4847 Use : "stop" ,
4948 Short : "Stop the service" ,
5049 Args : cobra .NoArgs ,
51- Run : cli . WrapRun ( func (ctx context. Context , _ []string ) error {
52- return runSystemctlVerb (ctx , "stop" )
53- }) ,
50+ RunE : func (cmd * cobra. Command , _ []string ) error {
51+ return runSystemctlVerb (cmd . Context () , "stop" )
52+ },
5453 })
5554
5655 cmd .AddCommand (& cobra.Command {
5756 Use : "restart" ,
5857 Short : "Restart the service" ,
5958 Args : cobra .NoArgs ,
60- Run : cli . WrapRun ( func (ctx context. Context , _ []string ) error {
61- return runSystemctlVerb (ctx , "restart" )
62- }) ,
59+ RunE : func (cmd * cobra. Command , args []string ) error {
60+ return runSystemctlVerb (cmd . Context () , "restart" )
61+ },
6362 })
6463
6564 cmd .AddCommand (& cobra.Command {
6665 Use : "status" ,
6766 Short : "Show status of the service" ,
6867 Args : cobra .NoArgs ,
69- Run : cli . WrapRun ( func (ctx context. Context , _ []string ) error {
68+ RunE : func (cmd * cobra. Command , args []string ) error {
7069 translateNonError := func (err error ) error {
7170 if err != nil {
7271 // LSB dictates that successful status show of non-running program must return 3:
@@ -81,21 +80,21 @@ func Entrypoint(serviceName string, makeAdditionalCommands func(string) []*cobra
8180 }
8281 }
8382
84- return translateNonError (runSystemctlVerb (ctx , "status" ))
85- }) ,
83+ return translateNonError (runSystemctlVerb (cmd . Context () , "status" ))
84+ },
8685 })
8786
8887 cmd .AddCommand (& cobra.Command {
8988 Use : "logs" ,
9089 Short : "Get logs for the service" ,
9190 Args : cobra .NoArgs ,
92- Run : cli . WrapRun ( func (ctx context. Context , _ []string ) error {
91+ RunE : func (cmd * cobra. Command , args []string ) error {
9392 //nolint:gosec // ok, is expected to not be user input.
94- logsCmd := exec .CommandContext (ctx , "journalctl" , "--unit=" + serviceName )
93+ logsCmd := exec .CommandContext (cmd . Context () , "journalctl" , "--unit=" + serviceName )
9594 logsCmd .Stdout = os .Stdout
9695 logsCmd .Stderr = os .Stderr
9796 return logsCmd .Run ()
98- }) ,
97+ },
9998 })
10099
101100 return cmd
@@ -108,7 +107,7 @@ func WithInstallAndUninstallCommands(makeSvc func(string) (*systemdinstaller.Ser
108107 Use : "install" ,
109108 Short : "Installs the background service" ,
110109 Args : cobra .NoArgs ,
111- Run : cli . WrapRun ( func (_ context. Context , _ []string ) error {
110+ RunE : func (_ * cobra. Command , args []string ) error {
112111 svc , err := makeSvc (serviceName )
113112 if err != nil {
114113 return err
@@ -121,7 +120,7 @@ func WithInstallAndUninstallCommands(makeSvc func(string) (*systemdinstaller.Ser
121120 fmt .Println (systemdinstaller .EnableAndStartCommandHints (* svc ))
122121
123122 return nil
124- }) ,
123+ },
125124 },
126125 // TODO: add uninstall command
127126 }
0 commit comments