Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Apr 6, 2023
1 parent 808b52e commit cb0bbd3
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 51 deletions.
6 changes: 3 additions & 3 deletions cmd/oras/root/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Example - Attach file to the manifest tagged 'v1' in an OCI layout folder 'layou
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
return runAttach(cmd, opts)
return runAttach(cmd.Context(), opts)
},
}

Expand All @@ -97,8 +97,8 @@ Example - Attach file to the manifest tagged 'v1' in an OCI layout folder 'layou
return cmd
}

func runAttach(cmd *cobra.Command, opts attachOptions) error {
ctx, _ := opts.WithContext(cmd.Context())
func runAttach(ctx context.Context, opts attachOptions) error {
ctx, _ = opts.WithContext(ctx)
annotations, err := opts.LoadManifestAnnotations()
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions cmd/oras/root/blob/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package blob

import (
"context"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -61,16 +62,16 @@ Example - Delete a blob and print its descriptor:
},
RunE: func(cmd *cobra.Command, args []string) error {
opts.targetRef = args[0]
return deleteBlob(cmd, opts)
return deleteBlob(cmd.Context(), opts)
},
}

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

func deleteBlob(cmd *cobra.Command, opts deleteBlobOptions) (err error) {
ctx, _ := opts.WithContext(cmd.Context())
func deleteBlob(ctx context.Context, opts deleteBlobOptions) (err error) {
ctx, _ = opts.WithContext(ctx)
repo, err := opts.NewRepository(opts.targetRef, opts.Common)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions cmd/oras/root/blob/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package blob

import (
"context"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -79,7 +80,7 @@ Example - Fetch and print a blob from OCI image layout archive file 'layout.tar'
},
Aliases: []string{"get"},
RunE: func(cmd *cobra.Command, args []string) error {
return fetchBlob(cmd, opts)
return fetchBlob(cmd.Context(), opts)
},
}

Expand All @@ -88,8 +89,8 @@ Example - Fetch and print a blob from OCI image layout archive file 'layout.tar'
return cmd
}

func fetchBlob(cmd *cobra.Command, opts fetchBlobOptions) (fetchErr error) {
ctx, _ := opts.WithContext(cmd.Context())
func fetchBlob(ctx context.Context, opts fetchBlobOptions) (fetchErr error) {
ctx, _ = opts.WithContext(ctx)
var target oras.ReadOnlyTarget
target, err := opts.NewReadonlyTarget(ctx, opts.Common)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/oras/root/blob/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package blob

import (
"context"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -84,7 +85,7 @@ Example - Push blob 'hi.txt' into an OCI layout folder 'layout-dir':
return option.Parse(&opts)
},
RunE: func(cmd *cobra.Command, args []string) error {
return pushBlob(cmd, opts)
return pushBlob(cmd.Context(), opts)
},
}

Expand All @@ -94,8 +95,8 @@ Example - Push blob 'hi.txt' into an OCI layout folder 'layout-dir':
return cmd
}

func pushBlob(cmd *cobra.Command, opts pushBlobOptions) (err error) {
ctx, _ := opts.WithContext(cmd.Context())
func pushBlob(ctx context.Context, opts pushBlobOptions) (err error) {
ctx, _ = opts.WithContext(ctx)

repo, err := opts.NewTarget(opts.Common)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/root/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Example - Copy an artifact with multiple tags with concurrency tuned:
return option.Parse(&opts)
},
RunE: func(cmd *cobra.Command, args []string) error {
return runCopy(cmd, opts)
return runCopy(cmd.Context(), opts)
},
}
cmd.Flags().BoolVarP(&opts.recursive, "recursive", "r", false, "[Preview] recursively copy the artifact and its referrer artifacts")
Expand All @@ -95,8 +95,8 @@ Example - Copy an artifact with multiple tags with concurrency tuned:
return cmd
}

func runCopy(cmd *cobra.Command, opts copyOptions) error {
ctx, _ := opts.WithContext(cmd.Context())
func runCopy(ctx context.Context, opts copyOptions) error {
ctx, _ = opts.WithContext(ctx)

// Prepare source
src, err := opts.From.NewReadonlyTarget(ctx, opts.Common)
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/root/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Example - Discover referrers of the manifest tagged 'v1' in an OCI layout folder
return option.Parse(&opts)
},
RunE: func(cmd *cobra.Command, args []string) error {
return runDiscover(cmd, opts)
return runDiscover(cmd.Context(), opts)
},
}

Expand All @@ -90,8 +90,8 @@ Example - Discover referrers of the manifest tagged 'v1' in an OCI layout folder
return cmd
}

func runDiscover(cmd *cobra.Command, opts discoverOptions) error {
ctx, _ := opts.WithContext(cmd.Context())
func runDiscover(ctx context.Context, opts discoverOptions) error {
ctx, _ = opts.WithContext(ctx)
repo, err := opts.NewReadonlyTarget(ctx, opts.Common)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions cmd/oras/root/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package root

import (
"bufio"
"context"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -65,15 +66,15 @@ Example - Log in with username and password in an interactive terminal and no TL
},
RunE: func(cmd *cobra.Command, args []string) error {
opts.Hostname = args[0]
return runLogin(cmd, opts)
return runLogin(cmd.Context(), opts)
},
}
option.ApplyFlags(&opts, cmd.Flags())
return cmd
}

func runLogin(cmd *cobra.Command, opts loginOptions) (err error) {
ctx, _ := opts.WithContext(cmd.Context())
func runLogin(ctx context.Context, opts loginOptions) (err error) {
ctx, _ = opts.WithContext(ctx)

// prompt for credential
if opts.Password == "" {
Expand Down
6 changes: 4 additions & 2 deletions cmd/oras/root/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.
package root

import (
"context"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"oras.land/oras/internal/credential"
Expand All @@ -41,7 +43,7 @@ Example - Logout:
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.hostname = args[0]
return runLogout(cmd, opts)
return runLogout(cmd.Context(), opts)
},
}

Expand All @@ -50,7 +52,7 @@ Example - Logout:
return cmd
}

func runLogout(cmd *cobra.Command, opts logoutOptions) error {
func runLogout(ctx context.Context, opts logoutOptions) error {
if opts.debug {
logrus.SetLevel(logrus.DebugLevel)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/oras/root/manifest/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package manifest

import (
"context"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -65,7 +66,7 @@ Example - Delete a manifest by digest 'sha256:99e4703fbf30916f549cd6bfa9cdbab614
},
RunE: func(cmd *cobra.Command, args []string) error {
opts.targetRef = args[0]
return deleteManifest(cmd, opts)
return deleteManifest(cmd.Context(), opts)
},
}

Expand All @@ -74,8 +75,8 @@ Example - Delete a manifest by digest 'sha256:99e4703fbf30916f549cd6bfa9cdbab614
return cmd
}

func deleteManifest(cmd *cobra.Command, opts deleteOptions) error {
ctx, _ := opts.WithContext(cmd.Context())
func deleteManifest(ctx context.Context, opts deleteOptions) error {
ctx, _ = opts.WithContext(ctx)
repo, err := opts.NewRepository(opts.targetRef, opts.Common)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions cmd/oras/root/manifest/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package manifest

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -78,7 +79,7 @@ Example - Fetch raw manifest from an OCI layout archive file 'layout.tar':
},
Aliases: []string{"get"},
RunE: func(cmd *cobra.Command, args []string) error {
return fetchManifest(cmd, opts)
return fetchManifest(cmd.Context(), opts)
},
}

Expand All @@ -88,8 +89,8 @@ Example - Fetch raw manifest from an OCI layout archive file 'layout.tar':
return cmd
}

func fetchManifest(cmd *cobra.Command, opts fetchOptions) (fetchErr error) {
ctx, _ := opts.WithContext(cmd.Context())
func fetchManifest(ctx context.Context, opts fetchOptions) (fetchErr error) {
ctx, _ = opts.WithContext(ctx)

target, err := opts.NewReadonlyTarget(ctx, opts.Common)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/root/manifest/fetch_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Example - Fetch and print the prettified descriptor of the config:
return option.Parse(&opts)
},
RunE: func(cmd *cobra.Command, args []string) error {
return fetchConfig(cmd, opts)
return fetchConfig(cmd.Context(), opts)
},
}

Expand All @@ -85,8 +85,8 @@ Example - Fetch and print the prettified descriptor of the config:
return cmd
}

func fetchConfig(cmd *cobra.Command, opts fetchConfigOptions) (fetchErr error) {
ctx, _ := opts.WithContext(cmd.Context())
func fetchConfig(ctx context.Context, opts fetchConfigOptions) (fetchErr error) {
ctx, _ = opts.WithContext(ctx)

repo, err := opts.NewReadonlyTarget(ctx, opts.Common)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/root/manifest/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Example - Push a manifest to an OCI layout folder 'layout-dir' and tag with 'v1'
return option.Parse(&opts)
},
RunE: func(cmd *cobra.Command, args []string) error {
return pushManifest(cmd, opts)
return pushManifest(cmd.Context(), opts)
},
}

Expand All @@ -103,8 +103,8 @@ Example - Push a manifest to an OCI layout folder 'layout-dir' and tag with 'v1'
return cmd
}

func pushManifest(cmd *cobra.Command, opts pushOptions) error {
ctx, _ := opts.WithContext(cmd.Context())
func pushManifest(ctx context.Context, opts pushOptions) error {
ctx, _ = opts.WithContext(ctx)
var target oras.Target
var err error
target, err = opts.NewTarget(opts.Common)
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/root/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Example - Pull artifact files from an OCI layout archive 'layout.tar':
return option.Parse(&opts)
},
RunE: func(cmd *cobra.Command, args []string) error {
return runPull(cmd, opts)
return runPull(cmd.Context(), opts)
},
}

Expand All @@ -101,8 +101,8 @@ Example - Pull artifact files from an OCI layout archive 'layout.tar':
return cmd
}

func runPull(cmd *cobra.Command, opts pullOptions) error {
ctx, _ := opts.WithContext(cmd.Context())
func runPull(ctx context.Context, opts pullOptions) error {
ctx, _ = opts.WithContext(ctx)
// Copy Options
var printed sync.Map
copyOptions := oras.DefaultCopyOptions
Expand Down
8 changes: 4 additions & 4 deletions cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Example - Push file "hi.txt" into an OCI layout folder 'layout-dir' with tag 'te
return option.Parse(&opts)
},
RunE: func(cmd *cobra.Command, args []string) error {
return runPush(cmd, opts)
return runPush(cmd.Context(), opts)
},
}
cmd.Flags().StringVarP(&opts.manifestConfigRef, "config", "", "", "`path` of image config file")
Expand All @@ -122,8 +122,8 @@ Example - Push file "hi.txt" into an OCI layout folder 'layout-dir' with tag 'te
return cmd
}

func runPush(cmd *cobra.Command, opts pushOptions) error {
ctx, _ := opts.WithContext(cmd.Context())
func runPush(ctx context.Context, opts pushOptions) error {
ctx, _ = opts.WithContext(ctx)
annotations, err := opts.LoadManifestAnnotations()
if err != nil {
return err
Expand Down Expand Up @@ -213,7 +213,7 @@ func runPush(cmd *cobra.Command, opts pushOptions) error {
return opts.ExportManifest(ctx, store, root)
}

func updateDisplayOption(cmd *cobra.Command, *oras.CopyGraphOptions, store content.Fetcher, verbose bool) {
func updateDisplayOption(opts *oras.CopyGraphOptions, store content.Fetcher, verbose bool) {
committed := &sync.Map{}
opts.PreCopy = display.StatusPrinter("Uploading", verbose)
opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
Expand Down
7 changes: 4 additions & 3 deletions cmd/oras/root/repo/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package repo

import (
"context"
"fmt"
"strings"

Expand Down Expand Up @@ -58,7 +59,7 @@ Example - List the repositories under the registry that include values lexically
if opts.hostname, opts.namespace, err = repository.ParseRepoPath(args[0]); err != nil {
return fmt.Errorf("could not parse repository path: %w", err)
}
return listRepository(cmd, opts)
return listRepository(cmd.Context(), opts)
},
}

Expand All @@ -67,8 +68,8 @@ Example - List the repositories under the registry that include values lexically
return cmd
}

func listRepository(cmd *cobra.Command, opts repositoryOptions) error {
ctx, _ := opts.WithContext(cmd.Context())
func listRepository(ctx context.Context, opts repositoryOptions) error {
ctx, _ = opts.WithContext(ctx)
reg, err := opts.Remote.NewRegistry(opts.hostname, opts.Common)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions cmd/oras/root/repo/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package repo

import (
"context"
"fmt"
"strings"

Expand Down Expand Up @@ -67,7 +68,7 @@ Example - Show tags associated with a digest:
return option.Parse(&opts)
},
RunE: func(cmd *cobra.Command, args []string) error {
return showTags(cmd, opts)
return showTags(cmd.Context(), opts)
},
}
cmd.Flags().StringVar(&opts.last, "last", "", "start after the tag specified by `last`")
Expand All @@ -76,8 +77,8 @@ Example - Show tags associated with a digest:
return cmd
}

func showTags(cmd *cobra.Command, opts showTagsOptions) error {
ctx, logger := opts.WithContext(cmd.Context())
func showTags(ctx context.Context, opts showTagsOptions) error {
ctx, logger := opts.WithContext(ctx)
finder, err := opts.NewReadonlyTarget(ctx, opts.Common)
if err != nil {
return err
Expand Down
Loading

0 comments on commit cb0bbd3

Please sign in to comment.