From 9bd14e842171b66233a17306d0e7ca1a4d5fe94d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 17 Dec 2020 10:11:09 +0200 Subject: [PATCH] flag: update vlib/flag/README.md --- vlib/flag/README.md | 68 ++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 38 deletions(-) diff --git a/vlib/flag/README.md b/vlib/flag/README.md index 595da63bb3..eca8623191 100644 --- a/vlib/flag/README.md +++ b/vlib/flag/README.md @@ -1,43 +1,35 @@ -module flag for command-line flag parsing - -- parsing flags like '--flag' or '--stuff=things' or '--things stuff' -- handles bool, int, float and string args -- is able to print usage -- handled unknown arguments as error +The `flag` module helps command-line flag parsing. +Main features are: +- parses flags like `-f` or '--flag' or '--stuff=things' or '--things stuff'. +- handles bool, int, float and string args. +- can print usage information listing all the declrared flags. +- handles unknown arguments as error. Usage example: - ```v - module main +```v +module main - import os - import flag +import os +import flag - fn main() { - mut fp := flag.new_flag_parser(os.args) - fp.application('flag_example_tool') - fp.version('v0.0.0') - fp.description('This tool is only designed to show how the flag lib is working') - - fp.skip_executable() - - an_int := fp.int('an_int', 0, 0o666, 'some int to define 0o666 is default') - a_bool := fp.bool('a_bool', 0, false, 'some \'real\' flag') - a_float := fp.float('a_float', 0, 1.0, 'also floats') - a_string := fp.string('a_string', `a`, 'no text', 'finally, some text with "a" an abbreviation') - - additional_args := fp.finalize() or { - eprintln(err) - println(fp.usage()) - return - } - - println(' - an_int: $an_int - a_bool: $a_bool - a_float: $a_float - a_string: \'$a_string\' - ') - println(additional_args.join_lines()) - } - ``` \ No newline at end of file +fn main() { + mut fp := flag.new_flag_parser(os.args) + fp.application('flag_example_tool') + fp.version('v0.0.0') + fp.description('This tool is only designed to show how the flag lib is working') + fp.skip_executable() + an_int := fp.int('an_int', 0, 0o123, 'some int to define 0o123 is its default value') + a_bool := fp.bool('a_bool', 0, false, 'some boolean flag. --a_bool will set it to true.') + a_float := fp.float('a_float', 0, 1.0, 'some floating point value, by default 1.0 .') + a_string := fp.string('a_string', `a`, 'no text', 'finally, some text with ' + + ' `-a` as an abbreviation, so you can pass --a_string abc or just -a abc') + additional_args := fp.finalize() or { + eprintln(err) + println(fp.usage()) + return + } + println('an_int: $an_int | a_bool: $a_bool | a_float: $a_float | a_string: "$a_string" ') + println(additional_args.join_lines()) +} +```