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

Include in program usage printout the default values of the options. #22977

Open
2 tasks
jorgeluismireles opened this issue Nov 26, 2024 · 0 comments
Open
2 tasks
Labels
Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one.

Comments

@jorgeluismireles
Copy link

jorgeluismireles commented Nov 26, 2024

Describe the feature

When using flag module and your program is running with help -h we need the program print the default values of the options. The users need to know what are the parameters default values they will not provide.

Use Case

https://play.vlang.io/p/eec968e1a6

import os
import flag

fn main() {
	mut fp := flag.new_flag_parser(os.args)
	fp.application('MyApp')
	fp.version('0.0.1')
	fp.description('My app is good')
	fp.skip_executable()
	param := fp.int('parameter', `p`, 34, 'My parameter')
	_ := fp.finalize() or { panic('${err}') }
	println('${param}')
}

If you run the above program it will print the default value of `param which is 34:

34

But if you run your program with -h the program prints the usage and exit:

MyApp 0.0.1
-----------------------------------------------
Usage: MyApp [options] [ARGS]

Description: My app is good

Options:
  -p, --parameter      My parameter
  -h, --help                display this help and exit
  --version                 output version information and exit

The playground prints the above if you set the page above textfield Run arguments with -h.

The issue is that line -p, --parameter My parameterdoes not include (as Golang does) the default value of this parameter.

Proposed Solution

In the printout, changes lines like this:

-p, --parameter      My parameter

into this:

-p, --parameter      My parameter (default 34)

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

V 0.4.8 e61475e

Environment details (OS name and version, etc.)

Playground

Huly®: V_0.6-21418

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@jorgeluismireles jorgeluismireles added the Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one. label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one.
Projects
None yet
Development

No branches or pull requests

1 participant