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

Refactor '(default: …)' flag string into utility function #1080

Merged
merged 1 commit into from
Mar 5, 2020

Conversation

saschagrunert
Copy link
Member

@saschagrunert saschagrunert commented Mar 2, 2020

What type of PR is this?

  • bug
  • cleanup
  • documentation
  • feature

What this PR does / why we need it:

The usage of the (default: …) strings are a bit error prone so we now
refactor them into a dedicated helper function.

Which issue(s) this PR fixes:

None

Release Notes

(REQUIRED)

None

The usage of the `(default: …)` strings are a bit error prone so we now
refactor them into a dedicated helper function.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
@saschagrunert saschagrunert requested a review from a team as a code owner March 2, 2020 12:07
@saschagrunert saschagrunert requested review from coilysiren and asahasrabuddhe and removed request for a team March 2, 2020 12:07
@codecov
Copy link

codecov bot commented Mar 2, 2020

Codecov Report

Merging #1080 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1080      +/-   ##
==========================================
+ Coverage   72.91%   72.93%   +0.02%     
==========================================
  Files          33       33              
  Lines        2481     2483       +2     
==========================================
+ Hits         1809     1811       +2     
  Misses        565      565              
  Partials      107      107
Impacted Files Coverage Δ
flag.go 86.39% <100%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 573004a...7742363. Read the comment docs.

Comment on lines +247 to +249
func formatDefault(format string) string {
return " (default: " + format + ")"
}
Copy link
Member

Choose a reason for hiding this comment

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

(non-blocking comment) do we know offhand why the different calls need different formatting verbs?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah we quote strings, but not bools for example. Because if the flag is a bool, then passing "true" will be interpreted as string and not bool.

Btw, I was wondering why we not print the default (like "" for string flags) values. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I think not printing the zero value makes sense because it's not unlikely that an application has logic that treats the zero value as something other than "".

For example, I have a CLI app with several string flags, including --file <path> and --install-completion <shell-name>. The "default" value for the config file is actually to recursively search up directories until it finds a file with a matching name. An empty string isn't accurate in this case, but that's how my app sees it. For --install-completion, the options are bash or zsh, but if nothing is passed, the flag doesn't run.

An empty string in both of those cases means something to me as an application developer, but not to the consumers of my CLI application, so I like the current behavior.

@rliebz rliebz merged commit 3cc9946 into urfave:master Mar 5, 2020
@saschagrunert saschagrunert deleted the refactor-flag-default branch March 5, 2020 13:24
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