refactor: container logs flagging process#1881
Conversation
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func newLogsCommand() *cobra.Command { |
There was a problem hiding this comment.
I think we can keep the file name unchanged as logs.go (and logs_test.go)
There was a problem hiding this comment.
Hmm, I was following the pattern in #1869 as container logs is the canonical name of this command. @AkihiroSuda Do you know which pattern we should follow?
There was a problem hiding this comment.
ops, didn't notice that. I'm okay with either one.
Currently it seems we only prefix container/image to file names if there're mutiple commands (e.g., container_inspect.go/container_prune.go v.s. image_inspect.go/image_prune.go; run.go instead of container_run.go).
But yeah adding a prefix can make those files closer :)
There was a problem hiding this comment.
My thoughts:
- Prefixing the files according to their canonical names may make them more organized.
- If we're grouping things according to their canonical names re. things under
pkg/cmd, maybe we want to do so consistently in other places.
Just my 2 cents :)
There was a problem hiding this comment.
Yes, containers_logs.go is preferred as it corresponds to the canonical form nerdctl containers logs
There was a problem hiding this comment.
Yes, @davidhsingyuchen, it's better to be merged after #1900
| if err != nil { | ||
| return err | ||
| } | ||
| return container.Logs(cmd.Context(), options, cmd.OutOrStdout(), cmd.ErrOrStderr()) |
There was a problem hiding this comment.
can you move the Container out from option and pass it as an argument? Container is not really an option but the target for Logs.
container.Logs(cmd.Context(), args[0], options, ...)
There was a problem hiding this comment.
I see. Shall we also move Containers out of ContainerInspectCommandOptions (in another PR)?
350debf to
faef906
Compare
| return logsCommand | ||
| } | ||
|
|
||
| func processContainerLogsCommandOptions(cmd *cobra.Command) (types.ContainerLogsCommandOptions, error) { |
There was a problem hiding this comment.
We may need to change ContainerLogsCommandOptions to ContainerLogsOptions (e.g. from ${Command}CommandOptions to ${Command}Options) for brevity. And also put stdin/stdout/stderr in ${Command}Options directly (if they're used).
#1889 has more discussion, but the tl;dr is:
- Rename
${Command}CommandOptionsto${Command}Options; - Put necessary
ioused by the command directly in${Command}Options; - Argument order:
func Command(ctx context.Context, param1, param2 type, options ${Command}Options(param1, param2 typemeans, e.g., container_id, image_ref, id, etc).
Sorry to back and forth on this, but now I think it brings more consistency :) lmk if there is something unclear.
There was a problem hiding this comment.
Thank you for the very clear summary! Updated accordingly.
Re. #1889 (comment):
These are optional, and nil values should imply os.Stdin, os.Stdout, os.Stderr .
I didn't add a check for this as they could be nil even before they are put into the options struct, and we weren't doing the checks. Checked #1900, and it seems that it's also not adding this check. Last, currently every caller in cmd/nerdctl should just explicitly specify them anyway.
faef906 to
57d72cb
Compare
57d72cb to
b5c8a42
Compare
|
Forced push again to
|
| return err | ||
| } | ||
| dataStore, err := clientutil.DataStore(globalOptions.DataRoot, globalOptions.Address) | ||
| func Logs(ctx context.Context, container string, options types.ContainerLogsOptions) error { |
There was a problem hiding this comment.
Can you add a brief comment here?
nit: also maybe change container name to something else (for example, c, arg), since the package name is also container. Not sure if there will any unexpected conflict.
There was a problem hiding this comment.
Can you add a brief comment here?
Do you mean adding a function comment for Logs? If yes, maybe we'd want to do it consistently. Currently it seems that no other function has such comment.
also maybe change container name to something else (for example, c, arg)
Maybe ctr? I feel that arg may be too generic, and c is a bit too short for a parameter.
There was a problem hiding this comment.
ctr also means ctr cli from containerd, which might be confusing. I'm okay with keeping container if there is no conflict.
There was a problem hiding this comment.
Rebased.
I'm okay with keeping container if there is no conflict.
Keeping it as is as there's no conflict.
b5c8a42 to
f242365
Compare
Signed-off-by: Hsing-Yu (David) Chen <davidhsingyuchen@gmail.com>
f242365 to
fb20478
Compare
Part of #1680
pkg/api/types/${cmd}_types.go, and define the CommandOption for this commandpkg/cmd/${cmd}, and move the command entry point in real into this packageNotes:
cmd/nerdctl/logs.gotocmd/nerdctl/container_logs.golike what's done in refactor: image tag flagging process #1869.Signed-off-by: Hsing-Yu (David) Chen davidhsingyuchen@gmail.com