vlang / coreutils

This repository contains programs equivalent to GNU coreutils, written in the V language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

--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.