[Refactor] Refactor the build subcommand flagging process#1792
Conversation
49e9265 to
efa8da1
Compare
|
Should be merged since #1793 |
efa8da1 to
baa801b
Compare
baa801b to
0c47b1c
Compare
|
should be merged after #1797 |
0c47b1c to
281b190
Compare
ad7542f to
d8da63a
Compare
|
Since #1797 has been merged, I think this PR is ready to go. |
49a21e9 to
cf82e2d
Compare
djdongjin
left a comment
There was a problem hiding this comment.
I found multiple "assign an option to a local variable (noCache := option.GOptions.NoCache) and then only use it once" pattern. We should remove those redundant assignment code unless for convenience because it's used several times.
Thanks
2951462 to
6d4194d
Compare
6d4194d to
35d0127
Compare
d09f613 to
6430c94
Compare
| namespace := options.GOptions.Namespace | ||
| address := options.GOptions.Address | ||
| platform := options.Platform |
There was a problem hiding this comment.
move into if output == block, they're only used in if (also suggest use options.xxx directly (same for options.BuildKitHost below) if they're not used frequently, that makes it more clear where the variable comes from)
There was a problem hiding this comment.
Noop, I think it will be used outside the if ouput==, see https://github.com/containerd/nerdctl/pull/1792/files#diff-3d28f1d0455b7f054ebac7695bbbe3d9c758b44b12602f7365d404a86011a49eR287-R289
There was a problem hiding this comment.
options.GOptions.Namespace and options.GOptions.Adress are only used within if output==. We can move these 2 inside.
(Although personally I will use options.Platform directly in line 285... 😅 it's so far away from its definition (line 185) and it's not changed in between)
| file := buildkitutil.DefaultDockerfileName | ||
| if options.File != "" { | ||
| if options.File == "-" { | ||
| var err error |
There was a problem hiding this comment.
do we need this line var err error?
There was a problem hiding this comment.
It's a special scope trick
if we don't have var err error, the code should be
if options.File == "-" {
var err error
dir, err := buildkitutil.WriteTempDockerfile(stdin)
if err != nil {
return "", nil, false, "", nil, nil, err
}
cleanup = func() {
os.RemoveAll(dir)
}
} else {
dir, file = filepath.Split(options.File)
}It means that the new dir variable will be unavailable outside the condition block....
9a62f11 to
d3922d9
Compare
Signed-off-by: Zheao.Li <me@manjusaka.me>
d3922d9 to
b9ce2af
Compare
Checklist:
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 packageSigned-off-by: Zheao.Li me@manjusaka.me