Skip to content

Commit b2c24a6

Browse files
status update
1 parent 59de0c5 commit b2c24a6

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

cmd/cluster_status.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ limitations under the License.
1717
package cmd
1818

1919
import (
20+
"encoding/json"
2021
"fmt"
2122

2223
"github.com/goccy/go-yaml"
24+
"github.com/grycap/oscar-cli/pkg/cluster"
2325
"github.com/grycap/oscar-cli/pkg/config"
2426
"github.com/spf13/cobra"
2527
)
@@ -40,15 +42,30 @@ func clusterStatusFunc(cmd *cobra.Command, args []string) error {
4042
return err
4143
}
4244

43-
output, err := yaml.Marshal(status)
44-
if err != nil {
45-
return fmt.Errorf("failed to serialize cluster status: %w", err)
45+
output, _ := cmd.Flags().GetString("output")
46+
switch output {
47+
case "json":
48+
if err := clusterInfoPrintJSON(cmd, status); err != nil {
49+
return err
50+
}
51+
default:
52+
outputyaml, err := yaml.Marshal(status)
53+
if err != nil {
54+
return fmt.Errorf("failed to serialize cluster status: %w", err)
55+
}
56+
fmt.Print(string(outputyaml))
57+
4658
}
4759

48-
fmt.Print(string(output))
4960
return nil
5061
}
5162

63+
func clusterInfoPrintJSON(cmd *cobra.Command, objects cluster.StatusInfo) error {
64+
encoder := json.NewEncoder(cmd.OutOrStdout())
65+
encoder.SetIndent("", " ")
66+
return encoder.Encode(objects)
67+
}
68+
5269
func makeClusterStatusCmd() *cobra.Command {
5370
clusterStatusCmd := &cobra.Command{
5471
Use: "status",
@@ -59,6 +76,7 @@ func makeClusterStatusCmd() *cobra.Command {
5976
}
6077

6178
clusterStatusCmd.Flags().StringP("cluster", "c", "", "set the cluster")
79+
clusterStatusCmd.Flags().StringP("output", "o", "table", "output format (json)")
6280

6381
return clusterStatusCmd
6482
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ require (
2222
require (
2323
github.com/gdamore/tcell/v2 v2.8.1
2424
github.com/golang-jwt/jwt/v5 v5.2.2
25-
github.com/grycap/oscar/v3 v3.3.0
25+
github.com/grycap/oscar/v3 v3.6.5
2626
github.com/indigo-dc/liboidcagent-go v0.3.0
2727
github.com/rivo/tview v0.42.0
2828
golang.org/x/term v0.28.0
29+
gopkg.in/yaml.v3 v3.0.1
2930
)
3031

3132
require (
@@ -58,14 +59,13 @@ require (
5859
github.com/rivo/uniseg v0.4.7 // indirect
5960
github.com/spf13/pflag v1.0.5 // indirect
6061
golang.org/x/crypto v0.31.0 // indirect
61-
golang.org/x/oauth2 v0.10.0 // indirect
62+
golang.org/x/oauth2 v0.27.0 // indirect
6263
golang.org/x/time v0.3.0 // indirect
6364
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
6465
google.golang.org/appengine v1.6.7 // indirect
6566
google.golang.org/protobuf v1.33.0 // indirect
6667
gopkg.in/inf.v0 v0.9.1 // indirect
6768
gopkg.in/yaml.v2 v2.4.0 // indirect
68-
gopkg.in/yaml.v3 v3.0.1 // indirect
6969
k8s.io/apimachinery v0.29.2 // indirect
7070
k8s.io/client-go v0.29.2 // indirect
7171
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ github.com/grycap/cdmi-client-go v0.1.1 h1:kHIrrLhvaCD0VyzEa5HOg7d/VgRE11yh9Ztdy
7474
github.com/grycap/cdmi-client-go v0.1.1/go.mod h1:ZqWeQS3YBJVXxg3HOIkAu1MLNJ4+7s848CyIPMFT5Gc=
7575
github.com/grycap/oscar/v3 v3.3.0 h1:+zDkUu6IryJ7Xq2QGNDkDCvhMrVhpjAU4cmiW2or+wc=
7676
github.com/grycap/oscar/v3 v3.3.0/go.mod h1:EN8kr1DLZc99llMJvXk4vnfVKQzEMLrnWdqaEKdg8YI=
77+
github.com/grycap/oscar/v3 v3.6.5 h1:iQDKY7Vqv/iWGLzyFoxONYQsHA8WunDhyOXP2JKGUis=
78+
github.com/grycap/oscar/v3 v3.6.5/go.mod h1:Js7D2jFlI5oCYw0QBFp1i3miRYtFLHF6HEALDbSoAis=
7779
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
7880
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
7981
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
@@ -197,6 +199,8 @@ golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
197199
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
198200
golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8=
199201
golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI=
202+
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
203+
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
200204
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
201205
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
202206
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

pkg/service/logs.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,10 @@ import (
3333

3434
const logsPath = "/system/logs"
3535

36-
type JobsResponse struct {
37-
Jobs map[string]*types.JobInfo `json:"jobs"`
38-
NextPage string `json:"next_page,omitempty"`
39-
RemainingJob *int64 `json:"remaining_jobs,omitempty"`
40-
}
41-
4236
var ErrNoLogsFound = errors.New("service has no logs")
4337

4438
// ListLogs returns a map with all the available logs from the given service
45-
func ListLogs(c *cluster.Cluster, name string, page string) (logMap JobsResponse, err error) {
39+
func ListLogs(c *cluster.Cluster, name string, page string) (logMap types.JobsResponse, err error) {
4640
listLogsURL, err := url.Parse(c.Endpoint)
4741
if err != nil {
4842
return logMap, cluster.ErrParsingEndpoint
@@ -76,7 +70,7 @@ func ListLogs(c *cluster.Cluster, name string, page string) (logMap JobsResponse
7670
return logMap, err
7771
}
7872
jobs := map[string]*types.JobInfo{}
79-
jobsResponse := JobsResponse{}
73+
jobsResponse := types.JobsResponse{}
8074
// Try to decode the response body into the jobsResponse
8175
err = json.NewDecoder(bytes.NewReader(body)).Decode(&jobsResponse)
8276
if err != nil {
@@ -91,7 +85,7 @@ func ListLogs(c *cluster.Cluster, name string, page string) (logMap JobsResponse
9185
if _, ok := jobs["jobs"]; ok {
9286
return jobsResponse, err
9387
} else {
94-
jobsResponse = JobsResponse{Jobs: jobs, NextPage: "", RemainingJob: nil}
88+
jobsResponse = types.JobsResponse{Jobs: jobs, NextPage: "", RemainingJob: nil}
9589
return jobsResponse, err
9690
}
9791

0 commit comments

Comments
 (0)