Skip to content

Commit 06bc2b4

Browse files
committed
Add "status" command
1 parent 4360345 commit 06bc2b4

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func NewRootCmd() *cobra.Command {
6464
rootCmd.AddCommand(NewRepoSyncCmd())
6565
rootCmd.AddCommand(NewSettingCmd())
6666
rootCmd.AddCommand(NewSignatureCmd())
67+
rootCmd.AddCommand(NewStatusCmd())
6768
rootCmd.AddCommand(NewSyncCmd())
6869
rootCmd.AddCommand(NewSystemCmd())
6970
rootCmd.AddCommand(NewValidateAutoinstallsCmd())

cmd/status.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
cobbler "github.com/cobbler/cobblerclient"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func NewStatusCmd() *cobra.Command {
10+
statusCmd := &cobra.Command{
11+
Use: "status",
12+
Short: "View installation status of Cobbler Profiles and Systems.",
13+
Long: `This command displays the current status of all Cobbler Profiles and Systems. All installations that
14+
run for longer then 100 minutes are considered stalled.`,
15+
RunE: func(cmd *cobra.Command, args []string) error {
16+
err := generateCobblerClient()
17+
if err != nil {
18+
return err
19+
}
20+
21+
res, err := Client.GetStatus(cobbler.StatusText)
22+
if err != nil {
23+
return err
24+
}
25+
fmt.Fprintln(cmd.OutOrStdout(), res.(string))
26+
27+
return nil
28+
},
29+
}
30+
return statusCmd
31+
}

cmd/status_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
"github.com/cobbler/cobblerclient"
6+
"github.com/spf13/cobra"
7+
"testing"
8+
)
9+
10+
func Test_StatusCmd(t *testing.T) {
11+
// Arrange
12+
cobra.OnInitialize(initConfig, setupLogger)
13+
rootCmd := NewRootCmd()
14+
rootCmd.SetArgs([]string{"--config", "../testing/.cobbler.yaml", "status"})
15+
stdout := bytes.NewBufferString("")
16+
stderr := bytes.NewBufferString("")
17+
rootCmd.SetOut(stdout)
18+
rootCmd.SetErr(stderr)
19+
expectedResult := "ip |target |start |state \n"
20+
21+
// Act
22+
err := rootCmd.Execute()
23+
24+
// Assert
25+
cobblerclient.FailOnError(t, err)
26+
FailOnNonEmptyStream(t, stderr)
27+
if stdout.String() != expectedResult {
28+
t.Errorf(`Expected "%s", got "%s"`, expectedResult, stdout.String())
29+
}
30+
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/cobbler/cli
33
go 1.22
44

55
require (
6-
github.com/cobbler/cobblerclient v0.5.5
6+
github.com/cobbler/cobblerclient v0.5.7
77
github.com/spf13/cobra v1.8.1
88
github.com/spf13/pflag v1.0.5
99
github.com/spf13/viper v1.19.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/cobbler/cobblerclient v0.5.5 h1:sMd+j3IcW8atuAbwiJWOL+vriqxTPi5jxEg10TdQUc0=
2-
github.com/cobbler/cobblerclient v0.5.5/go.mod h1:n6b8fTUOlg7BdMl6FeifUm4Uk1JY6/tlTlOClV4x2Wc=
1+
github.com/cobbler/cobblerclient v0.5.7 h1:0G/lvlmssCCpV8MiuqcOlL1P2BwwHh+V05aF3vHnr6k=
2+
github.com/cobbler/cobblerclient v0.5.7/go.mod h1:n6b8fTUOlg7BdMl6FeifUm4Uk1JY6/tlTlOClV4x2Wc=
33
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
44
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

0 commit comments

Comments
 (0)