AreFlagsValid checks that the provided flag combination is valid and returns an error otherwise
()
| 62 | // AreFlagsValid checks that the provided flag combination is valid |
| 63 | // and returns an error otherwise |
| 64 | func (opts *Options) AreFlagsValid() error { |
| 65 | // If provided, check that the Repo option is in the expected format <OWNER>/<REPO> |
| 66 | if opts.Repo != "" && !isProvidedRepoValid(opts.Repo) { |
| 67 | return fmt.Errorf("invalid value provided for repo: %s", opts.Repo) |
| 68 | } |
| 69 | |
| 70 | // If provided, check that the SignerRepo option is in the expected format <OWNER>/<REPO> |
| 71 | if opts.SignerRepo != "" && !isProvidedRepoValid(opts.SignerRepo) { |
| 72 | return fmt.Errorf("invalid value provided for signer-repo: %s", opts.SignerRepo) |
| 73 | } |
| 74 | |
| 75 | // Check that limit is between 1 and 1000 |
| 76 | if opts.Limit < 1 || opts.Limit > 1000 { |
| 77 | return fmt.Errorf("limit %d not allowed, must be between 1 and 1000", opts.Limit) |
| 78 | } |
| 79 | |
| 80 | // Check that the bundle-from-oci flag is only used with OCI artifact paths |
| 81 | if opts.UseBundleFromRegistry && !strings.HasPrefix(opts.ArtifactPath, "oci://") { |
| 82 | return fmt.Errorf("bundle-from-oci flag can only be used with OCI artifact paths") |
| 83 | } |
| 84 | |
| 85 | // Check that both the bundle-from-oci and bundle-path flags are not used together |
| 86 | if opts.UseBundleFromRegistry && opts.BundlePath != "" { |
| 87 | return fmt.Errorf("bundle-from-oci flag cannot be used with bundle-path flag") |
| 88 | } |
| 89 | |
| 90 | // Verify provided hostname |
| 91 | if opts.Hostname != "" { |
| 92 | if err := ghinstance.HostnameValidator(opts.Hostname); err != nil { |
| 93 | return fmt.Errorf("error parsing hostname: %w", err) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | func isProvidedRepoValid(repo string) bool { |
| 101 | // we expect a provided repository argument be in the format <OWNER>/<REPO> |