Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line parsing lib VLang

Tags:

vlang

I want to write a command line application with the V programming language. Is there a library for command line parsing?

like image 791
thinwybk Avatar asked Jul 26 '19 18:07

thinwybk


2 Answers

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.

like image 137
Xander Bielby Avatar answered Oct 02 '22 00:10

Xander Bielby


You can use the official flag module. See for example: https://github.com/vlang/v/blob/689003454b5c60fa13a6a0b44c39f79847806609/tools/performance_compare.v#L204

This produces something like this from the user perspective:

0[13:29:12] /v/nv $ tools/performance_compare --help
performance_compare 0.0.4
-----------------------------------------------
Usage: performance_compare [options] COMMIT_BEFORE [COMMIT_AFTER]

Description:
  Compares V executable size and performance,
  between 2 commits from V's local git history.
  When only one commit is given, it is compared to master.

The arguments should be at least 1 and at most 2 in number.

Options:
  --help <bool>:false       Show this help screen

  --vcrepo <string>:https://github.com/vlang/vc
                            The url of the vc repository. You can clone it
                            beforehand, and then just give the local folder
                            path here. That will eliminate the network ops
                            done by this tool, which is useful, if you want
                            to script it/run it in a restrictive vps/docker.

  --verbose <bool>:false    Be more verbose

  --hyperfine_options <string>:
                            Additional options passed to hyperfine.
                            For example on linux, you may want to pass:
                               --hyperfine_options "--prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches'"

  --workdir <string>:/tmp   A writable folder, where the comparison will be done.

0[13:29:13] /v/nv $
like image 22
Dangelov Avatar answered Oct 02 '22 00:10

Dangelov