Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: improve user interface for help message by add default text #456

Merged
merged 2 commits into from
May 6, 2023

Conversation

adamqqqplay
Copy link
Contributor

@adamqqqplay adamqqqplay commented Apr 24, 2023

  • pkg: introduce internal/constant package
  • cmd: improve user interface for help message by add default text

Current help message:

NAME:
   containerd-nydus-grpc - Nydus remote snapshotter for containerd

USAGE:
   containerd-nydus-grpc [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --root value                                directory to store snapshotter data and working states (default: /var/lib/containerd-nydus)
   --address value                             remote snapshotter gRPC socket path (default: /run/containerd-nydus/containerd-nydus-grpc.sock)
   --config value                              path to nydus-snapshotter configuration (such as: config.toml)
   --nydus-image nydus-image                   path to nydus-image binary, default to search in $PATH (such as: /usr/local/bin/nydus-image)
   --nydusd nydusd                             path to nydusd binary, default to search in $PATH (such as: /usr/local/bin/nydusd)
   --nydusd-config value, --config-path value  path to nydusd configuration (such as: nydusd-config.json or nydusd-config-v2.toml) (default: /etc/nydus/nydusd-config.json)
   --daemon-mode value                         nydusd daemon working mode, possible values: "multiple", "shared" or "none" (default: multiple)
   --fs-driver value                           driver to mount RAFS filesystem, possible values: "fusedev", "fscache" (default: fusedev)
   --log-level value                           logging level, possible values: "trace", "debug", "info", "warn", "error" (default: info)
   --log-to-stdout                             print log messages to standard output (default: false)
   --version                                   print version and build information (default: false)
   --help, -h                                  show help

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2023

Codecov Report

Merging #456 (e835623) into main (2455464) will increase coverage by 0.05%.
The diff coverage is 88.88%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #456      +/-   ##
==========================================
+ Coverage   37.01%   37.07%   +0.05%     
==========================================
  Files          60       60              
  Lines        6886     6892       +6     
==========================================
+ Hits         2549     2555       +6     
  Misses       4042     4042              
  Partials      295      295              
Impacted Files Coverage Δ
config/config.go 34.23% <ø> (ø)
pkg/daemon/config.go 0.00% <0.00%> (ø)
config/default.go 81.25% <86.66%> (ø)
internal/flags/flags.go 100.00% <100.00%> (ø)

@adamqqqplay adamqqqplay force-pushed the improve-help-message branch 2 times, most recently from 72a19f5 to b0bfbf2 Compare April 25, 2023 08:11
Destination: &args.SnapshotterConfigPath,
},
&cli.StringFlag{
Name: "nydusd-config",
Aliases: []string{"config-path"},
Usage: "path to the nydusd configuration",
Usage: "path to nydusd configuration (such as: nydusd-config.json or configuration_v2.toml)",
Copy link
Collaborator

Choose a reason for hiding this comment

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

nydusd-config.json or nydusd-config-v2.toml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -94,7 +94,7 @@ func main() {
return errors.Wrap(err, "set up logger")
}

log.L.Infof("Start nydus-snapshotter. PID %d Version %s FsDriver %s DaemonMode %s",
log.L.Infof("Start nydus-snapshotter. PID: %d Version :%s FsDriver: %s DaemonMode: %s",
Copy link
Member

Choose a reason for hiding this comment

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

Should we make the colon very close to "Version" like Version: PID: ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will fix it.

Destination: &args.RootDir,
DefaultText: "/var/lib/containerd-nydus",
Copy link
Member

Choose a reason for hiding this comment

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

This can't work and may violate the current theory of how nydus-snapshotter merges configurations from 1. default values, 2. TOML configuration file 3. CLI parameters. The way assigning a default value to CLI parameters will always override values from TOML configuration file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@changweige "DefaultText" will not affect the parsing of parameters, it is just a prompt message to let users know the value when no CLI parameters and configuration files are specified. The "Value" field is the real default value of the CLI.

Please refer to: https://cli.urfave.org/v2/examples/flags/#default-values-for-help-output

Copy link
Member

Choose a reason for hiding this comment

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

I see. Thanks for your elaboration. Can we use the default values defined in config/default.go as the DefaultText value? In order to avoid cyclic dependency, we can move function ParseParameters to flags package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Thanks for your elaboration. Can we use the default values defined in config/default.go as the DefaultText value? In order to avoid cyclic dependency, we can move function ParseParameters to flags package?

Good idea, I will try to do it.

Copy link
Member

@changweige changweige left a comment

Choose a reason for hiding this comment

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

In summary, we can't give a default value for CLI parameters unless we can judge if it is ever specified by users in ParseParameters()

Copy link
Member

@changweige changweige left a comment

Choose a reason for hiding this comment

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

Need rebase 🥹


package constant

const (
Copy link
Member

Choose a reason for hiding this comment

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

Why the source file is named as cmd.go ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the constants in this file are prepared for the cmd and config package, what name do you think is better?

Copy link
Member

Choose a reason for hiding this comment

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

how about values.go or constants.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

values.go looks good.

Move some string constants in CLI config to a new package
for easier future refactoring.

Signed-off-by: Qinqi Qu <quqinqi@linux.alibaba.com>
1. Fix missing default values in the --help after v0.6.1.
2. Sort out some usage information.

Signed-off-by: Qinqi Qu <quqinqi@linux.alibaba.com>
@changweige
Copy link
Member

@sctb512 Please check the optimizer E2E test. It randomly fails, which is somewhat upset.

Copy link
Member

@changweige changweige left a comment

Choose a reason for hiding this comment

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

LGTM

@changweige changweige merged commit e732202 into containerd:main May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants