-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added latest changes from main; added changes suggested from reviewdo…
…g pipeline about unused err in config_test.go Signed-off-by: Patrick Eschenbach <[email protected]>
- Loading branch information
Showing
9 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package project | ||
|
||
import ( | ||
"github.com/goharbor/harbor-cli/pkg/api" | ||
"github.com/goharbor/harbor-cli/pkg/utils" | ||
"github.com/goharbor/harbor-cli/pkg/views/project/list" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func SearchProjectCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "search", | ||
Short: "search project based on their names", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
projects, err := api.SearchProject(args[0]) | ||
if err != nil { | ||
log.Fatalf("failed to get projects: %v", err) | ||
} | ||
FormatFlag := viper.GetString("output-format") | ||
if FormatFlag != "" { | ||
utils.PrintPayloadInJSONFormat(projects) | ||
return | ||
} | ||
|
||
list.SearchProjects(projects.Payload.Project) | ||
}, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package repository | ||
|
||
import ( | ||
"github.com/goharbor/harbor-cli/pkg/api" | ||
"github.com/goharbor/harbor-cli/pkg/utils" | ||
"github.com/goharbor/harbor-cli/pkg/views/repository/search" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func SearchRepoCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "search", | ||
Short: "search repository based on their names", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
repo, err := api.SearchRepository(args[0]) | ||
if err != nil { | ||
log.Fatalf("failed to get repositories: %v", err) | ||
} | ||
FormatFlag := viper.GetString("output-format") | ||
if FormatFlag != "" { | ||
utils.PrintPayloadInJSONFormat(repo) | ||
return | ||
} | ||
|
||
search.SearchRepositories(repo.Payload.Repository) | ||
}, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package search | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/charmbracelet/bubbles/table" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/goharbor/go-client/pkg/sdk/v2.0/models" | ||
"github.com/goharbor/harbor-cli/pkg/views/base/tablelist" | ||
) | ||
|
||
var columns = []table.Column{ | ||
{Title: "Repository Name", Width: 30}, | ||
{Title: "Project Id", Width: 11}, | ||
{Title: "Project Name", Width: 16}, | ||
{Title: "Access Level", Width: 12}, | ||
{Title: "Artifact Count", Width: 14}, | ||
{Title: "Pull Count", Width: 12}, | ||
} | ||
|
||
func SearchRepositories(repos []*models.SearchRepository) { | ||
var rows []table.Row | ||
for _, repo := range repos { | ||
accessLevel := "public" | ||
if !repo.ProjectPublic { | ||
accessLevel = "private" | ||
} | ||
rows = append(rows, table.Row{ | ||
repo.RepositoryName, | ||
fmt.Sprintf("%d", repo.ProjectID), | ||
repo.ProjectName, | ||
accessLevel, | ||
fmt.Sprintf("%d", repo.ArtifactCount), | ||
strconv.FormatInt(repo.PullCount, 10), | ||
}) | ||
} | ||
|
||
m := tablelist.NewModel(columns, rows, len(rows)) | ||
if _, err := tea.NewProgram(m).Run(); err != nil { | ||
fmt.Println("Error running program:", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters