diff --git a/cmd/harbor/root/artifact/list.go b/cmd/harbor/root/artifact/list.go index c378f05e..d343faf7 100644 --- a/cmd/harbor/root/artifact/list.go +++ b/cmd/harbor/root/artifact/list.go @@ -34,6 +34,7 @@ func ListArtifactCommand() *cobra.Command { if err != nil { log.Errorf("failed to list artifacts: %v", err) + return } FormatFlag := viper.GetString("output-format") diff --git a/cmd/harbor/root/artifact/view.go b/cmd/harbor/root/artifact/view.go index 7d13c0f6..a16531b0 100644 --- a/cmd/harbor/root/artifact/view.go +++ b/cmd/harbor/root/artifact/view.go @@ -35,6 +35,7 @@ func ViewArtifactCommmand() *cobra.Command { if err != nil { log.Errorf("failed to get info of an artifact: %v", err) + return } FormatFlag := viper.GetString("output-format") diff --git a/cmd/harbor/root/labels/list.go b/cmd/harbor/root/labels/list.go index be9c996d..84f127bb 100644 --- a/cmd/harbor/root/labels/list.go +++ b/cmd/harbor/root/labels/list.go @@ -22,10 +22,13 @@ func ListLabelCommand() *cobra.Command { } FormatFlag := viper.GetString("output-format") if FormatFlag != "" { - utils.PrintPayloadInJSONFormat(label) - return + err = utils.PrintFormat(label, FormatFlag) + if err != nil { + log.Error(err) + } + } else { + list.ListLabels(label.Payload) } - list.ListLabels(label.Payload) }, } diff --git a/cmd/harbor/root/project/list.go b/cmd/harbor/root/project/list.go index 3a908b42..9fae2bf4 100644 --- a/cmd/harbor/root/project/list.go +++ b/cmd/harbor/root/project/list.go @@ -34,6 +34,7 @@ func ListProjectCommand() *cobra.Command { if err != nil { log.Fatalf("failed to get projects list: %v", err) + return } FormatFlag := viper.GetString("output-format") if FormatFlag != "" { diff --git a/cmd/harbor/root/project/logs.go b/cmd/harbor/root/project/logs.go index 8e4cac54..b333cb23 100644 --- a/cmd/harbor/root/project/logs.go +++ b/cmd/harbor/root/project/logs.go @@ -29,6 +29,7 @@ func LogsProjectCommmand() *cobra.Command { if err != nil { log.Fatalf("failed to get project logs: %v", err) + return } FormatFlag := viper.GetString("output-format") diff --git a/cmd/harbor/root/project/search.go b/cmd/harbor/root/project/search.go index 89ed7a67..0e1ce12a 100644 --- a/cmd/harbor/root/project/search.go +++ b/cmd/harbor/root/project/search.go @@ -20,13 +20,17 @@ func SearchProjectCommand() *cobra.Command { if err != nil { log.Fatalf("failed to get projects: %v", err) } + FormatFlag := viper.GetString("output-format") if FormatFlag != "" { - utils.PrintPayloadInJSONFormat(projects) - return + err = utils.PrintFormat(projects, FormatFlag) + if err != nil { + log.Error(err) + } + } else { + list.SearchProjects(projects.Payload.Project) } - list.SearchProjects(projects.Payload.Project) }, } return cmd diff --git a/cmd/harbor/root/registry/list.go b/cmd/harbor/root/registry/list.go index 78598511..c55036f6 100644 --- a/cmd/harbor/root/registry/list.go +++ b/cmd/harbor/root/registry/list.go @@ -21,6 +21,7 @@ func ListRegistryCommand() *cobra.Command { if err != nil { log.Fatalf("failed to get projects list: %v", err) + return } FormatFlag := viper.GetString("output-format") if FormatFlag != "" { diff --git a/cmd/harbor/root/repository/list.go b/cmd/harbor/root/repository/list.go index 41ca0492..f960d5e2 100644 --- a/cmd/harbor/root/repository/list.go +++ b/cmd/harbor/root/repository/list.go @@ -33,6 +33,7 @@ func ListRepositoryCommand() *cobra.Command { if err != nil { log.Errorf("failed to list repositories: %v", err) + return } FormatFlag := viper.GetString("output-format") diff --git a/cmd/harbor/root/repository/search.go b/cmd/harbor/root/repository/search.go index 9463741d..3071a813 100644 --- a/cmd/harbor/root/repository/search.go +++ b/cmd/harbor/root/repository/search.go @@ -19,14 +19,19 @@ func SearchRepoCmd() *cobra.Command { repo, err := api.SearchRepository(args[0]) if err != nil { log.Fatalf("failed to get repositories: %v", err) + return } + FormatFlag := viper.GetString("output-format") if FormatFlag != "" { - utils.PrintPayloadInJSONFormat(repo) - return + err = utils.PrintFormat(repo, FormatFlag) + if err != nil { + log.Error(err) + } + } else { + search.SearchRepositories(repo.Payload.Repository) } - search.SearchRepositories(repo.Payload.Repository) }, } return cmd diff --git a/cmd/harbor/root/schedule/list.go b/cmd/harbor/root/schedule/list.go index 91522054..88895fd2 100644 --- a/cmd/harbor/root/schedule/list.go +++ b/cmd/harbor/root/schedule/list.go @@ -17,16 +17,21 @@ func ListScheduleCommand() *cobra.Command { Short: "show all schedule jobs in Harbor", Run: func(cmd *cobra.Command, args []string) { schedule, err := api.ListSchedule(opts) + if err != nil { log.Fatalf("failed to get schedule list: %v", err) + return } + FormatFlag := viper.GetString("output-format") if FormatFlag != "" { - utils.PrintPayloadInJSONFormat(schedule) - return + err = utils.PrintFormat(schedule, FormatFlag) + if err != nil { + log.Error(err) + } + } else { + list.ListSchedule(schedule.Payload) } - - list.ListSchedule(schedule.Payload) }, }