Skip to content

refactor: pass an io.Writer to image.List#1887

Merged
AkihiroSuda merged 1 commit into
containerd:mainfrom
davidhsingyuchen:refactor-image-stdout
Jan 23, 2023
Merged

refactor: pass an io.Writer to image.List#1887
AkihiroSuda merged 1 commit into
containerd:mainfrom
davidhsingyuchen:refactor-image-stdout

Conversation

@davidhsingyuchen
Copy link
Copy Markdown
Contributor

@davidhsingyuchen davidhsingyuchen commented Jan 19, 2023

Part of #1856

Also rearrange the parameter order of printImages (i.e., move imageList to be right after ctx) according to the reason stated in #1837 (comment).

Signed-off-by: Hsing-Yu (David) Chen davidhsingyuchen@gmail.com

Comment thread pkg/cmd/image/list.go Outdated
}

func printImages(ctx context.Context, options types.ImageListCommandOptions, client *containerd.Client, imageList []images.Image) error {
func printImages(ctx context.Context, imageList []images.Image, options types.ImageListCommandOptions, client *containerd.Client, w io.Writer) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you move client to after ctx and before imageList? It's more consistent with other funcs where a client is used. (e.g., (ctx, client, container/image/etc, option, io, etc))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, updated.

@davidhsingyuchen davidhsingyuchen marked this pull request as ready for review January 19, 2023 21:12
Copy link
Copy Markdown
Member

@djdongjin djdongjin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on CI green, thanks

@AkihiroSuda AkihiroSuda added this to the v1.2.0 milestone Jan 19, 2023
Comment thread pkg/cmd/image/list.go Outdated
)

func List(ctx context.Context, options types.ImageListCommandOptions) error {
func List(ctx context.Context, options types.ImageListCommandOptions, stdout io.Writer) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func List(ctx context.Context, options types.ImageListCommandOptions, stdout io.Writer) error {
func List(ctx context.Context, stdout io.Writer, options types.ImageListCommandOptions) error {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda Shall we somehow (i.e., open an issue?) standardize the parameter order?

Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

@davidhsingyuchen davidhsingyuchen Jan 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed. Shall I also update printImages from

func printImages(ctx context.Context, client *containerd.Client, imageList []images.Image, options types.ImageListCommandOptions, w io.Writer) error {

to

func printImages(ctx context.Context, w io.Writer, client *containerd.Client, imageList []images.Image, options types.ImageListCommandOptions) error {

Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda Jan 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's discuss this in #1889 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated according to the summary in #1881 (comment), thanks!

@davidhsingyuchen davidhsingyuchen force-pushed the refactor-image-stdout branch 4 times, most recently from fa99db0 to d4fe593 Compare January 22, 2023 20:00
@davidhsingyuchen davidhsingyuchen requested review from AkihiroSuda and djdongjin and removed request for AkihiroSuda January 22, 2023 20:01
Copy link
Copy Markdown
Member

@djdongjin djdongjin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks. maybe we should merge #1900 first before merging this one, to avoid conflict on big PRs.

Comment thread pkg/cmd/image/list.go Outdated
switch options.Format {
case "", "table", "wide":
w = tabwriter.NewWriter(w, 4, 8, 4, ' ', 0)
options.Stdout = tabwriter.NewWriter(options.Stdout, 4, 8, 4, ' ', 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I feel we should keep and update the w variable (e.g., line 186-187) and use w here&below, instead of persisting the change in options.Stdout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, fixed.

@davidhsingyuchen davidhsingyuchen force-pushed the refactor-image-stdout branch 2 times, most recently from 0bab337 to c73b0ba Compare January 23, 2023 09:01
Signed-off-by: Hsing-Yu (David) Chen <davidhsingyuchen@gmail.com>
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 7cbe445 into containerd:main Jan 23, 2023
@davidhsingyuchen davidhsingyuchen deleted the refactor-image-stdout branch January 23, 2023 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants