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

Refactoring the option.Parse method #930

Merged
merged 4 commits into from
Feb 15, 2023

Conversation

godruoyi
Copy link
Contributor

The option.Parse method should return only failure or success without other logic.

Comment on lines 199 to 204
if opt.ShowVersion {
return version.Short, nil
}

if opt.ShowHelp {
return opt.flags.FlagUsages(), nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Removing these lines changes the logic, that it may fail to show the version or help information if the rest code returns an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @localvar, I think it's okay for the program to return an error if the user includes some incorrect commands when starting the service while checking the version or help information.

Copy link
Collaborator

Choose a reason for hiding this comment

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

we hope the show version and usage are simple so that they never fail, take show usage as an example: if the user doesn't know the usage, then it would be hard for him/her to understand what was wrong in the command line.

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 still think it's okay. Consider the following examples,

# Same behavior
easegress-server --help
easegress-server some-not-exists-command --help

# Different behaviors
// Previously, help information was displayed, but now an error is returned instead.
easegress-server -f not_exists_file.yaml --help  

where only an incorrectly specified configuration file could cause different behavior between the two.

If the user specifies an incorrect configuration file (or if the file content is incorrect), returning an error directly without showing help may is acceptable.

Copy link
Collaborator

@localvar localvar Feb 15, 2023

Choose a reason for hiding this comment

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

No, if the user wants the version and usage, we need always show the information, we all know there are jokes that a user asks where the any key is, so we need to keep the help information as easier to get as possible.

and from the current code, not only an incorrect configuration file will return an error.

and from the maintenance view, the code will change from time to time, even if only an incorrect configuration file returns an error now, developers may add other error cases later, and it is very possible for them to forget to update these codes at the same time, that'd result in a bad user experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have any good suggestions, or should we just close it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

	if opt.ShowVersion || opt.ShowHelp {
		return nil
	}

@@ -159,7 +158,7 @@ func New() *Options {

opt.flags.IntVar(&opt.StatusUpdateMaxBatchSize, "status-update-max-batch-size", 20, "Number of object statuses to update at maximum in one transaction.")

opt.viper.BindPFlags(opt.flags)
_ = opt.viper.BindPFlags(opt.flags)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why make this change and the changes at L183, L187?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a minor update because the IDE will display a warning if we don't handle the error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's ok, but may I know which IDE you are using? On my side, vs code never reported this warning, and this could not be a help as the error is still not handled.

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'm using IntelliJ IDEA, and here's an example where a warning is displayed in IntelliJ IDEA:
image

@godruoyi godruoyi requested review from localvar and removed request for suchen-sci February 15, 2023 03:40
@godruoyi godruoyi force-pushed the optimal_configuration_parse branch 3 times, most recently from 566cbaa to da3825d Compare February 15, 2023 08:44
@suchen-sci suchen-sci added this pull request to the merge queue Feb 15, 2023
Merged via the queue into easegress-io:main with commit 2760499 Feb 15, 2023
@godruoyi godruoyi deleted the optimal_configuration_parse branch February 17, 2023 05:05
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.

None yet

3 participants