Skip to content

Commit 789d425

Browse files
att
1 parent 3de9d17 commit 789d425

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ local exist = argv.flags_exist({ "case_sensitive", "cs" })
7171
print(exist)
7272
```
7373

74+
## Getting Flags by index Consider only the first
75+
Considerring only first arg of flag, can make your conde more solid, and
76+
easy to read:
77+
```lua
78+
---@type Argv
79+
argv = require("luargv")
80+
local index = 1
81+
local default = "test"
82+
local first_out_flag = argv.get_flag_arg_by_index_consider_only_first({ "out", "output", "o" }, index, default)
83+
print(first_out_flag)
84+
```
85+
86+
### Getting Flags Size Consider only the first
87+
```lua
88+
---@type Argv
89+
argv = require("luargv")
90+
local size = argv.get_flag_size_consider_only_first({ "out", "o" })
91+
print(size)
92+
```
93+
94+
7495
## Compact flags
7596
its also possible to get comppact flags (the gcc model), witch increases
7697
readiability of the software:

src/luargv/base_flags_consider_only_first.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ luargv.get_flag_arg_by_index_consider_only_first = function(flags, index, defaul
6060
::continue::
6161
end
6262

63-
return total_found
63+
return default
6464
end
6565

src/types.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
---@field get_flag_size fun(flags:string[]|string):number
33
---@field get_flag_arg_by_index fun(flags:string[]|string,index:number,default:string | nil):string|nil
44
---@field flags_exist fun(flags:string[]):boolean
5+
---@field get_flag_size_consider_only_first fun(flags:string[]|string):number
6+
---@field get_flag_arg_by_index_consider_only_first fun(flags:string[]|string,index:number,default:string | nil):string|nil
57
---@field one_of_args_exist fun(arg:string[] | string):boolean
68
---@field get_total_args_size fun():number
79
---@field get_arg_by_index_not_adding_to_used fun(index:number):string

0 commit comments

Comments
 (0)