Skip to content

Commit b0c1191

Browse files
Merge pull request #1 from gabreudev/reolucao_gabreudev
feat: resolucao
2 parents f00e9d2 + c4b017b commit b0c1191

File tree

3 files changed

+49
-48
lines changed

3 files changed

+49
-48
lines changed

examples/basic_usage.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- importa a lib
2+
local luargv = require("luargv")
3+
4+
-- simula args
5+
luargv.argslist = { "--name", "Gabriel", "-v" }
6+
7+
print("Total de args:", luargv.get_total_args_size())
8+
print("Arg[1]:", luargv.get_arg_by_index(1))
9+
print("Existe --name?", luargv.flags_exist({ "--name" }))
10+
print("Valor de --name:", luargv.get_flag_arg_by_index("--name", 1, "default"))

src/types.lua

Lines changed: 0 additions & 48 deletions
This file was deleted.

types.lua

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- ############################################
2+
-- Public types for the LuaArgv library
3+
-- ############################################
4+
5+
---@class Argv
6+
---@field argslist string[] Complete list of command-line arguments
7+
---@field used_args number[] Indices of arguments that have been used
8+
---@field flag_identifiers string[] Identifiers recognized as flags (e.g., {"-", "--"})
9+
---
10+
---@field get_flag_size fun(flags:string[]|string):number Returns the number of values associated with a flag
11+
---@field get_flag_arg_by_index fun(flags:string[]|string,index:number,default:string|nil):string|nil Returns the flag value by index
12+
---@field flags_exist fun(flags:string[]):boolean Checks if any of the flags exist
13+
---@field get_flag_size_consider_only_first fun(flags:string[]|string):number Returns the number of occurrences considering only the first flag
14+
---@field get_flag_arg_by_index_consider_only_first fun(flags:string[]|string,index:number,default:string|nil):string|nil Returns the argument for the first occurrence of the flag
15+
---@field one_of_args_exist fun(arg:string[]|string):boolean Checks if one of the arguments exists
16+
---@field get_total_args_size fun():number Returns the total number of arguments
17+
---@field get_arg_by_index fun(index:number):string|nil Returns argument by index
18+
---@field get_arg_by_index_not_adding_to_used fun(index:number):string Returns argument without marking it as used
19+
---@field get_compact_flags fun(flags:string[]|string,index:number,default:string|nil):string|nil Gets values of compact flags (e.g., -abc)
20+
---@field get_compact_flags_size fun(flags:string[]|string):number Returns the number of compact flags
21+
---@field add_used_args_by_index fun(used_flag:number) Marks an argument as used
22+
---@field get_total_unused_args fun():number Returns the number of unused arguments
23+
---@field get_unsed_arg_by_index fun(index:number):string|nil Returns unused argument by index
24+
---@field get_next_unused_index fun():number|nil Returns the index of the next unused argument
25+
---@field get_next_unused fun():string|nil Returns the next unused argument
26+
---@field type fun(value:any):string Returns the type of a value
27+
---@field substr_func fun(str:string,start:number,endnum:number):string Returns a substring of a string
28+
---@field get_str_size fun(str:string):number Returns the length of a string
29+
30+
---@type Argv
31+
luargv = luargv
32+
33+
34+
-- ############################################
35+
-- Main interface
36+
-- ############################################
37+
38+
---@class LuaArgvModule
39+
---@field argv Argv Public API to handle command-line arguments

0 commit comments

Comments
 (0)