vargs 0.5
A simple argument parsing library for
V
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
Installation
Via vpm:
v install nedpals.vargs
Via
vpkg
vpkg get vargs
# or
vpkg get https://github.com/nedpals/vargs
Changes in
0.5
- Breaking change on the usage of the library.
-
alias(orig, dest)
for mapping options to existing ones. - Array and the
start
index are now moved into the Args
struct as internal fields. - Default values are now moved inside the declaration of the
Args
struct.
Changes in
0.4
- Use comma-separated values of an option as array of strings with the
array_option(name)
function - Fixed unused variable error.
- Options values are now merged if the name of the option has already existed.
- Fixed problem when installing module from VPM. #2
- Final stable release? Hmmm
0.4.1
- Merge duplicate codes into a function.
- Fixed another unused variable error.
0.4.2
- Fixed parsing errors when used in complex scenarios.
- Add proper tests.
- Now only works with
0.1.22
and above. - Fixed maps formatting when converting
Args
to string. - Partial refactoring of code including converting
if
statements to match
0.4.3
- Fix breaking changes when compiling on V
0.1.23
Contributing
- Fork it (
https://github.com/nedpals/vargs/fork
) - Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Testing
To test the module, just type the following command:
v test vargs_test.v
License
Contributors
-
Ned Palacios
- creator and maintainer