Skip to content

Commit

Permalink
refactor(build/registry): add support for context with options
Browse files Browse the repository at this point in the history
Signed-off-by: Massimiliano Giovagnoli <[email protected]>
  • Loading branch information
maxgio92 committed Jun 23, 2023
1 parent 3738986 commit 48c224f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build/registry/cmd/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func main() {
defer out.Flush()

opts := options.NewCommonOptions(
options.WithContext(context.Background()),
options.WithOutput(out),
)

Expand Down Expand Up @@ -86,7 +87,7 @@ func main() {
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
RunE: func(c *cobra.Command, args []string) error {
status, err := oci.DoUpdateOCIRegistry(context.Background(), args[0])
status, err := oci.DoUpdateOCIRegistry(opts.Context, args[0])
if err != nil {
return err
}
Expand Down
10 changes: 9 additions & 1 deletion build/registry/internal/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ limitations under the License.
package options

import (
"context"
"io"
)

type CommonOptions struct {
Output io.Writer
Output io.Writer
Context context.Context
}

type CommonOption func(opts *CommonOptions)
Expand All @@ -41,3 +43,9 @@ func WithOutput(out io.Writer) CommonOption {
opts.Output = out
}
}

func WithContext(ctx context.Context) CommonOption {
return func(opts *CommonOptions) {
opts.Context = ctx
}
}

0 comments on commit 48c224f

Please sign in to comment.