template?
tomByrer opened this issue · comments
I've noticed there is no standard to the program structures. V is easy to understand, but would be better if the codebase looked the same though out. EG strange that even the version code is different between these 2 commands:
https://github.com/vlang/coreutils/blob/main/false/false.v#L7
https://github.com/vlang/coreutils/blob/main/whoami/whoami.v#L15
More standardized code would be easier to review, maintain, & automate (both in creation & testing).
PR #5 refers to the structure of whoami.v
and implements a simple function of printing available parameters, which can be used as a reference.
We are discussing things on discord about what we might need to add (including a template or a module, or whatever), whether we will start requiring a _test.v
file with each command, etc.
One of the things under discussion is whether we do command line parsing like whoami
or maybe use the flag
module like false
, true
, and yes
. Possibly switch to the cli
module for all.
I use flag
module in sleep
. It is simple and easy to use, but some frequently used options, such as --help
and --version
, need to be declared repeatedly in each CLI.
// ...
help_opt := fp.bool('help', 0, false, 'display this help and exit')
version_opt := fp.bool('version', 0, false, 'output version information and exit')
args := fp.finalize() or {
error_exit(err.msg)
exit(1)
}
if help_opt {
println(fp.usage())
exit(0)
}
if version_opt {
println('$cmd_ns $fp.application_version')
exit(0)
}
// ...
Yes, it would be nice if those were supported in the flag
module instead.
https://gist.github.com/Flinner/fa424110312de236e24d335d01f8dd97 this is the one i use
--help
and --version
are now supported by default. You can still define them yourself, but I recommend removing them from your gist as they won't be needed often.
The common
module takes care of setting up command line, handling --help
and --version
, etc.