Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ linters:
gosec:
excludes:
- G306
revive:
rules:
- name: var-naming
disabled: true

formatters:
enable:
Expand Down
2 changes: 1 addition & 1 deletion internal/banner/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func randomQuote() string {

// isTerminal checks if stdout is a terminal.
func isTerminal() bool {
return term.IsTerminal(int(os.Stdout.Fd()))
return term.IsTerminal(int(os.Stdout.Fd())) // #nosec G115 -- Fd() returns a small file descriptor, no overflow risk
}

// flush forces stdout to display buffered content immediately.
Expand Down
29 changes: 27 additions & 2 deletions internal/cli/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ import (

// newPsCommand creates the ps command.
func (c *CLI) newPsCommand() *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "ps",
Short: "List running deployments and their status",
Run: func(_ *cobra.Command, _ []string) {
Run: func(cmd *cobra.Command, _ []string) {
refresh, err := cmd.Flags().GetBool("refresh")
if err != nil {
log.Error().Msgf("%v", err)
return
}

deployments, err := c.app.StateManager.ListDeployments()
if err != nil {
log.Error().Msgf("%v", err)
Expand All @@ -41,12 +47,27 @@ func (c *CLI) newPsCommand() *cobra.Command {
}

status := "unknown"
statusErr := false
if s, err := provider.Status(template); err != nil {
log.Error().Msgf("%v", err)
statusErr = true
} else {
status = s
}

if refresh && status != "running" {
if statusErr {
log.Warn().Msgf("skipping refresh for %s on %s: status could not be determined", deployment.TemplateID, deployment.ProviderName)
} else {
if err := c.app.StateManager.RemoveDeployment(deployment.ProviderName, deployment.TemplateID); err != nil {
log.Error().Msgf("%v", err)
} else {
log.Info().Msgf("removed stale deployment %s on %s", deployment.TemplateID, deployment.ProviderName)
}
continue
}
}

t.AppendRow(table.Row{
deployment.ProviderName,
deployment.TemplateID,
Expand All @@ -64,4 +85,8 @@ func (c *CLI) newPsCommand() *cobra.Command {
t.Render()
},
}

cmd.Flags().BoolP("refresh", "r", false, "Remove stale deployments that are no longer running")

return cmd
}