Skip to content

Commit

Permalink
Merge pull request #837 from rsteube/add-supervisorctl
Browse files Browse the repository at this point in the history
added supervisorctl
  • Loading branch information
rsteube authored Mar 10, 2023
2 parents 5b4a4fb + 38bcc85 commit 708a0b8
Show file tree
Hide file tree
Showing 21 changed files with 556 additions and 0 deletions.
28 changes: 28 additions & 0 deletions completers/supervisorctl_completer/cmd/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/supervisor"
"github.com/spf13/cobra"
)

var addCmd = &cobra.Command{
Use: "add",
Short: "Activates any updates in config for process/group",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(addCmd).Standalone()

rootCmd.AddCommand(addCmd)

carapace.Gen(addCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
supervisor.ActionGroups(rootCmd.Flag("configuration").Value.String()),
supervisor.ActionProcesses(rootCmd.Flag("configuration").Value.String()),
).ToA().Invoke(c).Filter(c.Args).ToA()
}),
)
}
28 changes: 28 additions & 0 deletions completers/supervisorctl_completer/cmd/clear.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/supervisor"
"github.com/spf13/cobra"
)

var clearCmd = &cobra.Command{
Use: "clear",
Short: "Clear a process’ log files",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(clearCmd).Standalone()

rootCmd.AddCommand(clearCmd)

carapace.Gen(clearCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
supervisor.ActionProcesses(rootCmd.Flag("configuration").Value.String()).Invoke(c).Filter(c.Args).ToA(),
carapace.ActionValues("all"),
).ToA()
}),
)
}
25 changes: 25 additions & 0 deletions completers/supervisorctl_completer/cmd/fg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/supervisor"
"github.com/spf13/cobra"
)

var fgCmd = &cobra.Command{
Use: "fg",
Short: "Connect to a process in foreground mode Press Ctrl+C to exit foreground",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(fgCmd).Standalone()

rootCmd.AddCommand(fgCmd)

carapace.Gen(fgCmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return supervisor.ActionProcesses(rootCmd.Flag("configuration").Value.String())
}),
)
}
30 changes: 30 additions & 0 deletions completers/supervisorctl_completer/cmd/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var helpCmd = &cobra.Command{
Use: "help",
Short: "Print help for <action>",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(helpCmd).Standalone()

rootCmd.AddCommand(helpCmd)

carapace.Gen(helpCmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
vals := make([]string, 0)
for _, cmd := range helpCmd.Parent().Commands() {
if cmd != helpCmd && !cmd.Hidden {
vals = append(vals, cmd.Name(), cmd.Short)
}
}
return carapace.ActionValuesDescribed(vals...)
}),
)
}
28 changes: 28 additions & 0 deletions completers/supervisorctl_completer/cmd/pid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/supervisor"
"github.com/spf13/cobra"
)

var pidCmd = &cobra.Command{
Use: "pid",
Short: "Get the PID of supervisord",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(pidCmd).Standalone()

rootCmd.AddCommand(pidCmd)

carapace.Gen(pidCmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
supervisor.ActionProcesses(rootCmd.Flag("configuration").Value.String()),
carapace.ActionValues("all"),
).ToA()
}),
)
}
18 changes: 18 additions & 0 deletions completers/supervisorctl_completer/cmd/reload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var reloadCmd = &cobra.Command{
Use: "reload",
Short: "Restarts the remote supervisord",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(reloadCmd).Standalone()

rootCmd.AddCommand(reloadCmd)
}
28 changes: 28 additions & 0 deletions completers/supervisorctl_completer/cmd/remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/supervisor"
"github.com/spf13/cobra"
)

var removeCmd = &cobra.Command{
Use: "remove",
Short: "Activates any updates in config for process/group",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(removeCmd).Standalone()

rootCmd.AddCommand(removeCmd)

carapace.Gen(removeCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
supervisor.ActionGroups(rootCmd.Flag("configuration").Value.String()),
supervisor.ActionProcesses(rootCmd.Flag("configuration").Value.String()),
).ToA().Invoke(c).Filter(c.Args).ToA()
}),
)
}
18 changes: 18 additions & 0 deletions completers/supervisorctl_completer/cmd/reread.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var rereadCmd = &cobra.Command{
Use: "reread",
Short: "Reload the daemon’s configuration files, without add/remove (no restarts)",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(rereadCmd).Standalone()

rootCmd.AddCommand(rereadCmd)
}
29 changes: 29 additions & 0 deletions completers/supervisorctl_completer/cmd/restart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/supervisor"
"github.com/spf13/cobra"
)

var restartCmd = &cobra.Command{
Use: "restart",
Short: "Restart a process",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(restartCmd).Standalone()

rootCmd.AddCommand(restartCmd)

carapace.Gen(restartCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
supervisor.ActionGroups(rootCmd.Flag("configuration").Value.String()),
supervisor.ActionProcesses(rootCmd.Flag("configuration").Value.String()),
carapace.ActionValues("all"),
).ToA().Invoke(c).Filter(c.Args).ToA()
}),
)
}
32 changes: 32 additions & 0 deletions completers/supervisorctl_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "supervisorctl",
Short: "control applications run by supervisord from the cmd line",
Long: "http://supervisord.org/",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().StringP("configuration", "c", "", "configuration file path")
rootCmd.Flags().BoolP("help", "h", false, "print usage message and exit")
rootCmd.Flags().BoolP("history-file", "r", false, "keep a readline history")
rootCmd.Flags().BoolP("interactive", "i", false, "start an interactive shell after executing commands")
rootCmd.Flags().StringP("password", "p", "", "password to use for authentication with server")
rootCmd.Flags().StringP("serverurl", "s", "", "URL on which supervisord server is listening")
rootCmd.Flags().StringP("username", "u", "", "username to use for authentication with server")

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"configuration": carapace.ActionFiles(),
})
}
23 changes: 23 additions & 0 deletions completers/supervisorctl_completer/cmd/signal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/supervisor"
"github.com/spf13/cobra"
)

var signalCmd = &cobra.Command{
Use: "signal",
Short: "Signal process",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(signalCmd).Standalone()

rootCmd.AddCommand(signalCmd)

carapace.Gen(signalCmd).PositionalCompletion(
supervisor.ActionSignals(),
)
}
29 changes: 29 additions & 0 deletions completers/supervisorctl_completer/cmd/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/supervisor"
"github.com/spf13/cobra"
)

var startCmd = &cobra.Command{
Use: "start",
Short: "Start a process",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(startCmd).Standalone()

rootCmd.AddCommand(startCmd)

carapace.Gen(startCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
supervisor.ActionGroups(rootCmd.Flag("configuration").Value.String()),
supervisor.ActionProcesses(rootCmd.Flag("configuration").Value.String()),
carapace.ActionValues("all"),
).ToA().Invoke(c).Filter(c.Args).ToA()
}),
)
}
18 changes: 18 additions & 0 deletions completers/supervisorctl_completer/cmd/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var statusCmd = &cobra.Command{
Use: "status",
Short: "Get all process status info",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(statusCmd).Standalone()

rootCmd.AddCommand(statusCmd)
}
29 changes: 29 additions & 0 deletions completers/supervisorctl_completer/cmd/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/supervisor"
"github.com/spf13/cobra"
)

var stopCmd = &cobra.Command{
Use: "stop",
Short: "Stop a process",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(stopCmd).Standalone()

rootCmd.AddCommand(stopCmd)

carapace.Gen(stopCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
supervisor.ActionGroups(rootCmd.Flag("configuration").Value.String()),
supervisor.ActionProcesses(rootCmd.Flag("configuration").Value.String()),
carapace.ActionValues("all"),
).ToA().Invoke(c).Filter(c.Args).ToA()
}),
)
}
Loading

0 comments on commit 708a0b8

Please sign in to comment.