Skip to content

Commit

Permalink
feat(cli): refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Laurentiu Niculae <[email protected]>
  • Loading branch information
laurentiuNiculae committed Aug 8, 2023
1 parent ed90e3b commit 4e2a212
Show file tree
Hide file tree
Showing 38 changed files with 2,899 additions and 203 deletions.
7 changes: 5 additions & 2 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
ErrInvalidArgs = errors.New("cli: Invalid Arguments")
ErrInvalidFlagsCombination = errors.New("cli: Invalid combination of flags")
ErrInvalidURL = errors.New("cli: invalid URL format")
ErrExtensionNotEnabled = errors.New("cli: functionality is not built in current version")
ErrExtensionNotEnabled = errors.New("cli: functionality is not built in current server version")
ErrUnauthorizedAccess = errors.New("auth: unauthorized access. check credentials")
ErrCannotResetConfigKey = errors.New("cli: cannot reset given config key")
ErrConfigNotFound = errors.New("cli: config with the given name does not exist")
Expand Down Expand Up @@ -74,7 +74,7 @@ var (
ErrEmptyRepoName = errors.New("metadb: repo name can't be empty string")
ErrEmptyTag = errors.New("metadb: tag can't be empty string")
ErrEmptyDigest = errors.New("metadb: digest can't be empty string")
ErrInvalidRepoRefFormat = errors.New("invalid image reference format")
ErrInvalidRepoRefFormat = errors.New("invalid image reference format [repo:tag] or [repo@digest]")
ErrLimitIsNegative = errors.New("pageturner: limit has negative value")
ErrOffsetIsNegative = errors.New("pageturner: offset has negative value")
ErrSortCriteriaNotSupported = errors.New("pageturner: the sort criteria is not supported")
Expand Down Expand Up @@ -110,4 +110,7 @@ var (
ErrInvalidPublicKeyContent = errors.New("signatures: invalid public key content")
ErrInvalidStateCookie = errors.New("auth: state cookie not present or differs from original state")
ErrSyncNoURLsLeft = errors.New("sync: no valid registry urls left after filtering local ones")
ErrInvalidCLIParameter = errors.New("cli: invalid parameter")
ErrGQLEndpointNotFound = errors.New("cli: the server doesn't have a gql endpoint")
ErrGQLQueryNotSupported = errors.New("cli: query is not supported or has different arguments")
)
2 changes: 2 additions & 0 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import "github.com/spf13/cobra"
func enableCli(rootCmd *cobra.Command) {
rootCmd.AddCommand(NewConfigCommand())
rootCmd.AddCommand(NewImageCommand(NewSearchService()))
rootCmd.AddCommand(NewImagesCommand(NewSearchService()))
rootCmd.AddCommand(NewCveCommand(NewSearchService()))
rootCmd.AddCommand(NewCVESCommand(NewSearchService()))
rootCmd.AddCommand(NewRepoCommand(NewSearchService()))
rootCmd.AddCommand(NewSearchCommand(NewSearchService()))
}
4 changes: 2 additions & 2 deletions pkg/cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func doHTTPRequest(req *http.Request, verifyTLS bool, debug bool,

if debug {
fmt.Fprintln(configWriter, "[debug] ", req.Method, req.URL, "[status] ",
resp.StatusCode, " ", "[respoonse header] ", resp.Header)
resp.StatusCode, " ", "[response header] ", resp.Header)
}

defer resp.Body.Close()
Expand All @@ -136,7 +136,7 @@ func doHTTPRequest(req *http.Request, verifyTLS bool, debug bool,

bodyBytes, _ := io.ReadAll(resp.Body)

return nil, errors.New(string(bodyBytes)) //nolint: goerr113
return nil, errors.New(resp.Status + " " + string(bodyBytes)) //nolint: goerr113
}

if resultsPtr == nil {
Expand Down
13 changes: 13 additions & 0 deletions pkg/cli/cmdflags/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cmdflags

const (
URLFlag = "url"
ConfigFlag = "config"
UserFlag = "user"
OutputFormatFlag = "output"
FixedFlag = "fixed"
VerboseFlag = "verbose"
VersionFlag = "version"
DebugFlag = "debug"
SearchedCVEID = "id"
)
2 changes: 1 addition & 1 deletion pkg/cli/cve_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const (
cveDBRetryInterval = 3
cveDBRetryInterval = 1
)

func NewCveCommand(searchService SearchService) *cobra.Command {
Expand Down
Loading

0 comments on commit 4e2a212

Please sign in to comment.