Add RUNNING column to ls output

This commit is contained in:
Joel Elkins 2022-07-21 17:17:26 -05:00
parent a09c2a7225
commit 959ffec79b
2 changed files with 7 additions and 7 deletions

View File

@ -47,9 +47,9 @@ ccl ls squid`,
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 4, ' ', 0) w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 4, ' ', 0)
defer w.Flush() defer w.Flush()
fmt.Fprintf(w, "CATEGORY\tNAME\tIMAGE\n") fmt.Fprintf(w, "CATEGORY\tNAME\tIMAGE\tRUNNING\n")
for _, c := range conts { for _, c := range conts {
fmt.Fprintf(w, "%s\t%s\t%s\n", c.Category, c.Name, c.Image) fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", c.Category, c.Name, c.Image, c.IsRunning())
} }
}, },
} }

View File

@ -85,7 +85,7 @@ func (c *Container) RecreateCommands() []command.Command {
wasRunning := false wasRunning := false
return []command.Command{ return []command.Command{
command.NewFunc("stash_run_state", func() string { command.NewFunc("stash_run_state", func() string {
wasRunning = c.isRunning() wasRunning = c.IsRunning()
runMsg := "not running. Will not start it after recreating." runMsg := "not running. Will not start it after recreating."
if wasRunning { if wasRunning {
runMsg = "running. Will restart after recreating." runMsg = "running. Will restart after recreating."
@ -114,7 +114,7 @@ func (c *Container) StartCommands() []command.Command {
} }
return []command.Command{ return []command.Command{
command.NewConditional("start_unless_running", command.NewConditional("start_unless_running",
c.isRunning, c.IsRunning,
command.NewNop(), command.NewNop(),
command.NewSet(c.upCommands), command.NewSet(c.upCommands),
), ),
@ -129,7 +129,7 @@ func (c *Container) RestartCommands() []command.Command {
} }
} }
func (c *Container) isRunning() bool { func (c *Container) IsRunning() bool {
pid, err := c.Pid() pid, err := c.Pid()
if err != nil { if err != nil {
return false return false
@ -141,7 +141,7 @@ func (c *Container) UpdateCommands() []command.Command {
wasRunning := false wasRunning := false
return []command.Command{ return []command.Command{
command.NewFunc("stash_run_state", func() string { command.NewFunc("stash_run_state", func() string {
wasRunning = c.isRunning() wasRunning = c.IsRunning()
runMsg := "not running" runMsg := "not running"
if wasRunning { if wasRunning {
runMsg = "running" runMsg = "running"
@ -161,7 +161,7 @@ func (c *Container) UpdateCommands() []command.Command {
func (c *Container) StopCommands() []command.Command { func (c *Container) StopCommands() []command.Command {
return []command.Command{ return []command.Command{
command.NewConditional("stop_if_running", command.NewConditional("stop_if_running",
c.isRunning, c.IsRunning,
command.NewShell("podman stop "+c.Name), command.NewShell("podman stop "+c.Name),
command.NewNop(), command.NewNop(),
), ),