A simple argument parsing library for V. Ported from this file which was originally written on Typescript.
The version of this module will remain in
0.x.x
unless the language API's are finalized and implemented.
// dummy.v
import vargs // or import nedpals.vargs for vpm users
import os
fn main() {
// Second argument removes the first argument which contains the path of the executable.
mut _args := vargs.new(os.args, 1)
// Use the `alias` method if you want to map an option to an existing option.
_args.alias('W', 'with')
// Parsing is now a separate step
_args.parse()
println(_args.str())
println(_args.command)
println(_args.unknown[0])
println('with? ' + _args.options['with'])
}
./dummy cook chicken --with love -W soul
# { command: "cook", options: {"with" => "love"}, unknown: ["chicken"] }
# cook
# chicken
# with? love,soul
Via vpm:
v install nedpals.vargs
Via vpkg:
vpkg get vargs
# or
vpkg get https://github.com/nedpals/vargs
0.5
alias(orig, dest)
for mapping options to existing ones.start
index are now moved into the Args
struct as internal fields.Args
struct.0.4
array_option(name)
function0.4.1
0.4.2
0.1.22
and above.Args
to string.if
statements to match
0.4.3
0.1.23
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)To test the module, just type the following command:
v test vargs_test.v