Skip to content

Commit

Permalink
Move OutputJSON and OutputSummary to status package
Browse files Browse the repository at this point in the history
Signed-off-by: Raphaël Pinson <[email protected]>
  • Loading branch information
raphink committed Feb 6, 2023
1 parent a98d358 commit 2cad140
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
9 changes: 2 additions & 7 deletions clustermesh/clustermesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,6 @@ type Parameters struct {
Output string
}

const (
OutputJSON = "json"
OutputSummary = "summary"
)

func (p Parameters) validateParams() error {
if p.ApiserverImage != defaults.ClusterMeshApiserverImage {
return nil
Expand All @@ -505,7 +500,7 @@ func NewK8sClusterMesh(client k8sClusterMeshImplementation, p Parameters) *K8sCl
}

func (k *K8sClusterMesh) Log(format string, a ...interface{}) {
if k.params.Output == OutputSummary {
if k.params.Output == status.OutputSummary {
fmt.Fprintf(k.params.Writer, format+"\n", a...)
}
}
Expand Down Expand Up @@ -1312,7 +1307,7 @@ func (k *K8sClusterMesh) Status(ctx context.Context) (*Status, error) {

s.Connectivity, err = k.statusConnectivity(ctx)

if k.params.Output == OutputJSON {
if k.params.Output == status.OutputJSON {
jsonStatus, err := json.MarshalIndent(s, "", " ")
if err != nil {
return nil, fmt.Errorf("failed to marshal status to JSON")
Expand Down
1 change: 1 addition & 0 deletions internal/cli/cmd/clustermesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/cilium/cilium-cli/clustermesh"
"github.com/cilium/cilium-cli/defaults"
"github.com/cilium/cilium-cli/status"
)

func newCmdClusterMesh() *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newCmdStatus() *cobra.Command {
fmt.Print(s.Format())
fatalf("Unable to determine status: %s", err)
}
if params.Output == "json" {
if params.Output == status.OutputJSON {
jsonStatus, err := json.MarshalIndent(s, "", " ")
if err != nil {
// Report the most recent status even if an error occurred.
Expand All @@ -55,7 +55,7 @@ func newCmdStatus() *cobra.Command {
cmd.Flags().IntVar(&params.WorkerCount,
"worker-count", status.DefaultWorkerCount,
"The number of workers to use")
cmd.Flags().StringVarP(&params.Output, "output", "o", "summary", "Output format. One of: json, summary")
cmd.Flags().StringVarP(&params.Output, "output", "o", status.OutputSummary, "Output format. One of: json, summary")

return cmd
}
5 changes: 5 additions & 0 deletions status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const (
Reset = "\033[0m"
)

const (
OutputJSON = "json"
OutputSummary = "summary"
)

// MapCount is a map to count number of occurrences of a string
type MapCount map[string]int

Expand Down

0 comments on commit 2cad140

Please sign in to comment.