|
33 | 33 | ``` |
34 | 34 |
|
35 | 35 | ## Geting flags |
36 | | -you can get flags |
| 36 | +you can get flags by: |
| 37 | +```lua |
| 38 | +---@type Argv |
| 39 | +argv = require("luargv") |
| 40 | +local out_flags, size = argv.get_flag_args({ "out", "output", "o" }) |
| 41 | +for i = 1, size do |
| 42 | + print(out_flags[i]) |
| 43 | +end |
| 44 | +``` |
| 45 | +if you run: |
| 46 | +```shell |
| 47 | +lua teste.lua -out test test2 |
| 48 | +``` |
| 49 | +it will appear these: |
| 50 | +```txt |
| 51 | +test |
| 52 | +test2 |
| 53 | +``` |
| 54 | + |
| 55 | +## Checking if a flag exist |
| 56 | +you can check if a flag its present our not, by: |
| 57 | +```lua |
| 58 | +---@type Argv |
| 59 | +argv = require("luargv") |
| 60 | + |
| 61 | +---@type boolean |
| 62 | +local exist = argv.flags_exist({ "case_sensitive", "cs" }) |
| 63 | +print(exist) |
| 64 | +``` |
| 65 | +## Compact flags |
| 66 | +its also possible to get comppact flags (the gcc model), witch increases |
| 67 | +readiability of the software: |
| 68 | + |
| 69 | +```lua |
| 70 | +---@type Argv |
| 71 | +argv = require("luargv") |
| 72 | + |
| 73 | +confs, size = argv.get_compact_flags("conf:") |
| 74 | +for i = 1, size do |
| 75 | + print(confs[i]) |
| 76 | +end |
| 77 | +``` |
| 78 | +if you run: |
| 79 | +```shell |
| 80 | +lua teste.lua conf:test a b conf:test2 |
| 81 | +``` |
| 82 | +if will show: |
| 83 | +```txt |
| 84 | +test |
| 85 | +test2 |
| 86 | +``` |
| 87 | +## Configuring the project |
| 88 | +these lib its project to run idependent from the native lua lib, so you |
| 89 | +can configure , every aspect of the code |
| 90 | + |
| 91 | +```lua |
| 92 | +---@type Argv |
| 93 | +argv = require("luargv") |
| 94 | +argv.substr_func = string.gsub |
| 95 | +argv.get_str_size = string.len |
| 96 | +argv.argslist = { "a", "b", "c" } |
| 97 | +argv.flag_identifiers = { "--", "-" } |
| 98 | + |
| 99 | +local size = argv.get_total_args_size() |
| 100 | +for i = 1, size do |
| 101 | + print(argv.get_arg_by_index(i)) |
| 102 | +end |
| 103 | + |
| 104 | +``` |
0 commit comments