Command line parsing lib VLang
yes, the os module. this example outputs each command line argument
import os
fn main() {
for arg in os.args {
println(arg)
}
}
when run on my system: program.exe hello!
returns
D:\Documents\V\program.exe
hello!
Edit: I now see what you were aiming for with command line parsing. No, there are no existing modules that allow you to do this.
As of November 2020, the command-line arguments parsing is included in the standard library.
Example from V repository
import cli { Command, Flag }
import os
fn main() {
mut cmd := Command{
name: 'cli'
description: 'An example of the cli library.'
version: '1.0.0'
}
mut greet_cmd := Command{
name: 'greet'
description: 'Prints greeting in different languages.'
usage: '<name>'
required_args: 1
pre_execute: greet_pre_func
execute: greet_func
post_execute: greet_post_func
}
greet_cmd.add_flag(Flag{
flag: .string
required: true
name: 'language'
abbrev: 'l'
description: 'Language of the message.'
})
greet_cmd.add_flag(Flag{
flag: .int
name: 'times'
value: '3'
description: 'Number of times the message gets printed.'
})
cmd.add_command(greet_cmd)
cmd.parse(os.args)
}
Output
$ v run ./examples/cli.v
Usage: cli [flags] [commands]
An example of the cli library.
Flags:
-help Prints help information.
-version Prints version information.
Commands:
greet Prints greeting in different languages.
help Prints help information.
version Prints version information.