Skip to content

Commit 9b3cf54

Browse files
committed
fix: implement changes and apply lint fixes
implement changes Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> view-cmd terminal change fixed Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> lint fix Signed-off-by: Rizul Gupta <mail2rizul@gmail.com>
1 parent 0b47ef2 commit 9b3cf54

5 files changed

Lines changed: 21 additions & 21 deletions

File tree

cmd/harbor/root/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import (
1717
"fmt"
1818
"time"
1919

20-
"github.com/goharbor/harbor-cli/cmd/harbor/root/scanner"
2120
"github.com/goharbor/harbor-cli/cmd/harbor/root/artifact"
2221
"github.com/goharbor/harbor-cli/cmd/harbor/root/config"
2322
"github.com/goharbor/harbor-cli/cmd/harbor/root/labels"
2423
"github.com/goharbor/harbor-cli/cmd/harbor/root/project"
2524
"github.com/goharbor/harbor-cli/cmd/harbor/root/registry"
2625
repositry "github.com/goharbor/harbor-cli/cmd/harbor/root/repository"
26+
"github.com/goharbor/harbor-cli/cmd/harbor/root/scanner"
2727
"github.com/goharbor/harbor-cli/cmd/harbor/root/schedule"
2828
"github.com/goharbor/harbor-cli/cmd/harbor/root/user"
2929
"github.com/goharbor/harbor-cli/pkg/utils"

cmd/harbor/root/scanner/view.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ package scanner
1616
import (
1717
"github.com/goharbor/harbor-cli/pkg/api"
1818
"github.com/goharbor/harbor-cli/pkg/prompt"
19+
"github.com/goharbor/harbor-cli/pkg/utils"
1920
"github.com/goharbor/harbor-cli/pkg/views/scanner/view"
2021
log "github.com/sirupsen/logrus"
2122
"github.com/spf13/cobra"
23+
"github.com/spf13/viper"
2224
)
2325

2426
func ViewCommand() *cobra.Command {
2527
cmd := &cobra.Command{
2628
Use: "view",
2729
Short: "get scanner by id",
2830
Args: cobra.MaximumNArgs(1),
29-
Run: func(cmd *cobra.Command, args []string) {
31+
RunE: func(cmd *cobra.Command, args []string) error {
3032
var err error
3133
var registrationID string
3234
if len(args) > 0 {
@@ -38,7 +40,16 @@ func ViewCommand() *cobra.Command {
3840
if err != nil {
3941
log.Errorf("failed to get scanner: %v", err)
4042
}
41-
view.ViewScanner(response.Payload)
43+
formatFlag := viper.GetString("output-format")
44+
if formatFlag != "" {
45+
err = utils.PrintFormat(response, formatFlag)
46+
if err != nil {
47+
return err
48+
}
49+
} else {
50+
view.ViewScanner(response.Payload)
51+
}
52+
return nil
4253
},
4354
}
4455
return cmd

pkg/views/scanner/list/view.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ func ListScanners(scanners []*models.ScannerRegistration) {
4545
rows = append(rows, table.Row{
4646
s.Name,
4747
s.Description,
48-
fmt.Sprintf("%v", *s.IsDefault),
48+
fmt.Sprintf("%v", *s.Disabled),
4949
fmt.Sprintf("%v", s.URL),
50+
fmt.Sprintf("%v", *s.IsDefault),
5051
fmt.Sprintf("%v", *s.UseInternalAddr),
5152
fmt.Sprintf("%v", createdAt),
52-
fmt.Sprintf("%v", *s.Disabled),
5353
})
5454
}
5555

pkg/views/scanner/metadata/view.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ package metadata
1515

1616
import (
1717
"fmt"
18-
"os"
1918

2019
"github.com/charmbracelet/bubbles/table"
2120
tea "github.com/charmbracelet/bubbletea"
@@ -60,10 +59,7 @@ func DisplayScannerMetadata(md *models.ScannerAdapterMetadata) {
6059
propTable: tablelist.NewModel(propCols, propRows, len(propRows)),
6160
}
6261

63-
if _, err := tea.NewProgram(m).Run(); err != nil {
64-
fmt.Println("Error running program:", err)
65-
os.Exit(1)
66-
}
62+
fmt.Println(m.View())
6763
}
6864

6965
type metadataModel struct {

pkg/views/scanner/view/view.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func ViewScanner(scanner *models.ScannerRegistration) {
4646
scanner.Name,
4747
scanner.UUID,
4848
utils.FormatUrl(scanner.URL.String()),
49-
boolToStr(*scanner.IsDefault),
50-
boolToStr(*scanner.Disabled),
51-
boolToStr(*scanner.SkipCertVerify),
52-
boolToStr(*scanner.UseInternalAddr),
49+
fmt.Sprintf("%v", *scanner.IsDefault),
50+
fmt.Sprintf("%v", *scanner.Disabled),
51+
fmt.Sprintf("%v", *scanner.SkipCertVerify),
52+
fmt.Sprintf("%v", *scanner.UseInternalAddr),
5353
createdAt,
5454
updatedAt,
5555
})
@@ -61,10 +61,3 @@ func ViewScanner(scanner *models.ScannerRegistration) {
6161
os.Exit(1)
6262
}
6363
}
64-
65-
func boolToStr(b bool) string {
66-
if b {
67-
return "true"
68-
}
69-
return "false"
70-
}

0 commit comments

Comments
 (0)