[refactor] Add global flag process helper function#1797
Conversation
djdongjin
left a comment
There was a problem hiding this comment.
(Not request changes)
In the current PR, most commands are refactored into a half-way state (e.g., global flag is processed (sometimes, repeatedly) whenever it's needed. Ideally, it should only be processed once at the entry of the command, and let other usage use the processed struct.
As an example, getVolumeStore calls processGlobalFlags, and getComposer calls getVolumeStore, which means each compose commands call processGlobalFlags at least twice (one in getVolumeStore, one in its own command if global flags are used).
Either way, we should highlight that helper functions (e.g., getVolumeStore) should be refactored to not call processGlobalFlags directly and instead use the struct created by the command.
8e7c61e to
5fceed2
Compare
nice catch. I have update all the PR to make sure call processGlobalFlags once for each command |
3e9c335 to
b9b3be1
Compare
djdongjin
left a comment
There was a problem hiding this comment.
LGTM aside from the nit. thanks
b9b3be1 to
209ba73
Compare
|
@AkihiroSuda PTAL |
| hostsDir, err := cmd.Flags().GetStringSlice("hosts-dir") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| experimental, err := cmd.Flags().GetBool("experimental") | ||
| if err != nil { | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
Could we add hosts-dir and experimental flags to README? https://github.com/containerd/nerdctl#global-flags
There was a problem hiding this comment.
I think we can add the docs in another PR.
209ba73 to
ac8542c
Compare
Signed-off-by: Zheao.Li <me@manjusaka.me>
ac8542c to
dc374a5
Compare
I'm so sorry I have to make a huge PR again.
After #1793, we have a
types.GlobalCommandOptions, and for #1792 and #1791 and many refactor PR int he future, we may need to introduce a new helper function to process the global flag.In this PR, I introduce the new helper function and use this function to process the global flag in all subcommand.
There may be some duplicated code for some subcommand like
nerdctl run, I think this should be not a problem, I will merge it when I refactor the run command,Signed-off-by: Zheao.Li me@manjusaka.me