Skip to content

Commit

Permalink
move argument check to the pre run
Browse files Browse the repository at this point in the history
Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
  • Loading branch information
yuehaoliang committed Aug 8, 2022
1 parent 88f4e60 commit a2dbd63
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions cmd/oras/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type pushOptions struct {

targetRef string
manifestConfigRef string
artifactTpye string
artifactType string
}

func pushCmd() *cobra.Command {
Expand Down Expand Up @@ -74,6 +74,9 @@ Example - Push file to the HTTP registry:
`,
Args: cobra.MinimumNArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
if opts.artifactType != "" && opts.manifestConfigRef != "" {
return errors.New("--artifact-type and --manifest-config cannot both be provided")
}
return opts.ReadPassword()
},
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -84,17 +87,13 @@ Example - Push file to the HTTP registry:
}

cmd.Flags().StringVarP(&opts.manifestConfigRef, "manifest-config", "", "", "manifest config file")
cmd.Flags().StringVarP(&opts.artifactTpye, "artifact-type", "", "", "media type of config or manifest")
cmd.Flags().StringVarP(&opts.artifactType, "artifact-type", "", "", "media type of config or manifest")

option.ApplyFlags(&opts, cmd.Flags())
return cmd
}

func runPush(opts pushOptions) error {
if opts.artifactTpye != "" && opts.manifestConfigRef != "" {
return errors.New("--artifact-type and --manifest-config cannot be both provided")
}

ctx, _ := opts.SetLoggerLevel()
annotations, err := opts.LoadManifestAnnotations()
if err != nil {
Expand Down Expand Up @@ -142,8 +141,8 @@ func packManifest(ctx context.Context, store *file.Store, annotations map[string
packOpts.ConfigAnnotations = annotations[annotationConfig]
packOpts.ManifestAnnotations = annotations[annotationManifest]

if opts.artifactTpye != "" {
packOpts.ConfigMediaType = opts.artifactTpye
if opts.artifactType != "" {
packOpts.ConfigMediaType = opts.artifactType
}
if opts.manifestConfigRef != "" {
path, mediatype := parseFileReference(opts.manifestConfigRef, oras.MediaTypeUnknownConfig)
Expand Down

0 comments on commit a2dbd63

Please sign in to comment.