Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "status" command #62

Merged
merged 1 commit into from
Nov 14, 2024
Merged
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
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func NewRootCmd() *cobra.Command {
rootCmd.AddCommand(NewRepoSyncCmd())
rootCmd.AddCommand(NewSettingCmd())
rootCmd.AddCommand(NewSignatureCmd())
rootCmd.AddCommand(NewStatusCmd())
rootCmd.AddCommand(NewSyncCmd())
rootCmd.AddCommand(NewSystemCmd())
rootCmd.AddCommand(NewValidateAutoinstallsCmd())
Expand Down
31 changes: 31 additions & 0 deletions cmd/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"fmt"
cobbler "github.com/cobbler/cobblerclient"
"github.com/spf13/cobra"
)

func NewStatusCmd() *cobra.Command {
statusCmd := &cobra.Command{
Use: "status",
Short: "View installation status of Cobbler Profiles and Systems.",
Long: `This command displays the current status of all Cobbler Profiles and Systems. All installations that
run for longer then 100 minutes are considered stalled.`,
RunE: func(cmd *cobra.Command, args []string) error {
err := generateCobblerClient()
if err != nil {
return err
}

res, err := Client.GetStatus(cobbler.StatusText)
if err != nil {
return err
}
fmt.Fprintln(cmd.OutOrStdout(), res.(string))

return nil
},
}
return statusCmd
}
30 changes: 30 additions & 0 deletions cmd/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import (
"bytes"
"github.com/cobbler/cobblerclient"
"github.com/spf13/cobra"
"testing"
)

func Test_StatusCmd(t *testing.T) {
// Arrange
cobra.OnInitialize(initConfig, setupLogger)
rootCmd := NewRootCmd()
rootCmd.SetArgs([]string{"--config", "../testing/.cobbler.yaml", "status"})
stdout := bytes.NewBufferString("")
stderr := bytes.NewBufferString("")
rootCmd.SetOut(stdout)
rootCmd.SetErr(stderr)
expectedResult := "ip |target |start |state \n"
tiltingpenguin marked this conversation as resolved.
Show resolved Hide resolved

// Act
err := rootCmd.Execute()

// Assert
cobblerclient.FailOnError(t, err)
FailOnNonEmptyStream(t, stderr)
if stdout.String() != expectedResult {
t.Errorf(`Expected "%s", got "%s"`, expectedResult, stdout.String())
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/cobbler/cli
go 1.22

require (
github.com/cobbler/cobblerclient v0.5.5
github.com/cobbler/cobblerclient v0.5.7
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/cobbler/cobblerclient v0.5.5 h1:sMd+j3IcW8atuAbwiJWOL+vriqxTPi5jxEg10TdQUc0=
github.com/cobbler/cobblerclient v0.5.5/go.mod h1:n6b8fTUOlg7BdMl6FeifUm4Uk1JY6/tlTlOClV4x2Wc=
github.com/cobbler/cobblerclient v0.5.7 h1:0G/lvlmssCCpV8MiuqcOlL1P2BwwHh+V05aF3vHnr6k=
github.com/cobbler/cobblerclient v0.5.7/go.mod h1:n6b8fTUOlg7BdMl6FeifUm4Uk1JY6/tlTlOClV4x2Wc=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
Loading