Skip to content

Commit d017ee6

Browse files
committed
docs: update docs
1 parent 115c1f8 commit d017ee6

File tree

9 files changed

+84
-1
lines changed

9 files changed

+84
-1
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ bump-patch:
2424
.PHONY: build
2525
build:
2626
./build -y ./dist/lobash.bash
27+
28+
.PHONY: gen
29+
gen:
30+
./tools/gen

config.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ PREFIX: l.
4040
- [ ] if
4141
- [ ] is_array
4242
- [ ] is_array.s
43+
- [ ] is_associative_array
44+
- [ ] is_associative_array.s
4345
- [ ] is_bash
4446
- [ ] is_bash.s
4547
- [ ] is_dir
@@ -165,6 +167,7 @@ PREFIX: l.
165167
- [ ] Util
166168
- [ ] benchmark
167169
- [ ] compose
170+
- [ ] parse_args
168171
- [ ] parse_params
169172
- [ ] repeat
170173
- [ ] sedi
@@ -174,4 +177,5 @@ PREFIX: l.
174177
- [ ] Variable
175178
- [ ] cur_function_name
176179
- [ ] random
180+
- [ ] var_attrs
177181
- [ ] xdg_config_home

docs/module-usages/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Module Usages
22

3-
15 Categories, 139 Modules, 779 Test Cases.
3+
15 Categories, 143 Modules, 802 Test Cases.
44

55
Each module provides only one function which naming prefixed with `l.` by default.
66

@@ -49,6 +49,8 @@ Most Lobash modules support Bash 4.0+ except below modules.
4949
- [if](./condition.md#if)
5050
- [is_array](./condition.md#is_array)
5151
- [is_array.s](./condition.md#is_arrays)
52+
- [is_associative_array](./condition.md#is_associative_array)
53+
- [is_associative_array.s](./condition.md#is_associative_arrays)
5254
- [is_bash](./condition.md#is_bash)
5355
- [is_bash.s](./condition.md#is_bashs)
5456
- [is_dir](./condition.md#is_dir)
@@ -164,6 +166,7 @@ Most Lobash modules support Bash 4.0+ except below modules.
164166
- [Util](./util.md)
165167
- [benchmark](./util.md#benchmark)
166168
- [compose](./util.md#compose)
169+
- [parse_args](./util.md#parse_args)
167170
- [parse_params](./util.md#parse_params)
168171
- [repeat](./util.md#repeat)
169172
- [sedi](./util.md#sedi)
@@ -172,4 +175,5 @@ Most Lobash modules support Bash 4.0+ except below modules.
172175
- [Variable](./variable.md)
173176
- [cur_function_name](./variable.md#cur_function_name)
174177
- [random](./variable.md#random)
178+
- [var_attrs](./variable.md#var_attrs)
175179
- [xdg_config_home](./variable.md#xdg_config_home)

docs/module-usages/condition.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- [if](#if)
1414
- [is_array](#is_array)
1515
- [is_array.s](#is_arrays)
16+
- [is_associative_array](#is_associative_array)
17+
- [is_associative_array.s](#is_associative_arrays)
1618
- [is_bash](#is_bash)
1719
- [is_bash.s](#is_bashs)
1820
- [is_dir](#is_dir)
@@ -135,6 +137,7 @@
135137

136138
- Usage: `l.is_array <var_name>`
137139
- Description: When the variable is array or associative array, it returns 0 (true). Otherwise it returns 1 (false). This function should never throw exception error.
140+
- Dependent: [`var_attrs`](./variable.md#var_attrs)
138141
- Since: 0.3.0
139142
- Bash: 4.0+
140143
- **Notice**:
@@ -156,6 +159,30 @@
156159
- Test Cases: [tests/modules/is_array.s.bats](../../tests/modules/is_array.s.bats)
157160
- Source Code: [src/modules/is_array.s.bash](../../src/modules/is_array.s.bash)
158161

162+
### is_associative_array
163+
164+
- Usage: `l.is_associative_array <var_name>`
165+
- Description: When the variable is associative array, it returns 0 (true). Otherwise it returns 1 (false). This function should never throw exception error.
166+
- Dependent: [`var_attrs`](./variable.md#var_attrs)
167+
- Since: 0.7.0
168+
- Bash: 4.0+
169+
- **Notice**:
170+
- **Only with bash 4.3, this function return 1 when the variable declared without initialization.**
171+
- **Because `declare -p a` shows `declare: a: not found` when `declare -a a`. It's a bug in bash 4.3.**
172+
- Source Code: [src/modules/is_associative_array.bash](../../src/modules/is_associative_array.bash)
173+
174+
### is_associative_array.s
175+
176+
- Usage: `l.is_associative_array.s <var_name>`
177+
- Description: When the variable is array or associative array, it prints `true`. Otherwise it prints `false`. And it always exit with code 0.
178+
- Dependent: [`is_associative_array`](./condition.md#is_associative_array)
179+
- Since: 0.7.0
180+
- Bash: 4.0+
181+
- **Notice**:
182+
- **Only with bash 4.3, this function will echo `false` when the variable declared without initialization.**
183+
- **Because `declare -p a` shows `declare: a: not found` when `declare -a a`. It's a bug in bash 4.3.**
184+
- Source Code: [src/modules/is_associative_array.s.bash](../../src/modules/is_associative_array.s.bash)
185+
159186
### is_bash
160187

161188
- Usage: `l.is_bash`
@@ -259,6 +286,7 @@
259286
- Description:
260287
- Check whether a shell variable is exported.
261288
- Return 0 (true) or 1 (false). This function should never throw exception error.
289+
- Dependent: [`var_attrs`](./variable.md#var_attrs)
262290
- Since: 0.5.0
263291
- Bash: 4.0+
264292
- **Notice**:

docs/module-usages/util.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- [benchmark](#benchmark)
88
- [compose](#compose)
9+
- [parse_args](#parse_args)
910
- [parse_params](#parse_params)
1011
- [repeat](#repeat)
1112
- [sedi](#sedi)
@@ -32,6 +33,28 @@
3233
- Test Cases: [tests/modules/compose.bats](../../tests/modules/compose.bats)
3334
- Source Code: [src/modules/compose.bash](../../src/modules/compose.bash)
3435

36+
### parse_args
37+
38+
- Usage: `l.parse_args <definition> "$@"`
39+
- Description:
40+
- the `definition` is an associative array, which likes {[opts]=opts_name [args]=args_name ['-f,--flag']='bool'}.
41+
- The `[opts]` and `[args]` are required for `<definition>`.
42+
- It parses all parameters "$@". Put arguments to the `args_name` and options to `opts_name`.
43+
- The `opts_name` must be an associative array or `_`. If set `_`, the options will be ignored.
44+
- The `args_name` must be an array or `_`. If set `_`, the arguments will be ignored.
45+
- The option has tree type:
46+
- "bool": For example, `-f`, `--flag` means `${f}` and `${flag}` equal to `"true"` and `--no-f` and `--no-flag` equal to `"false"`.
47+
- "count": the value of option defaults to 0. And increasing count by times. For example: `-v` `-vv` `-vvv`.
48+
- "kv": key/value. It means the option must has an argument. If user not pass argument to "kv" option. It will print error and stop.
49+
- See test cases for details.
50+
- Dependent: [`each`](./array.md#each) [`match_list`](./string.md#match_list) [`var_attrs`](./variable.md#var_attrs)
51+
- Since: 0.7.0
52+
- Bash: 4.0+
53+
- **Notice**: **Only with bash 4.3, there may be something wrong if opts and args are not array.**
54+
- Test Cases: [tests/modules/parse_args.bats](../../tests/modules/parse_args.bats)
55+
- Source Code: [src/modules/parse_args.bash](../../src/modules/parse_args.bash)
56+
- Example: [example/modules/parse_args](../../example/modules/parse_args)
57+
3558
### parse_params
3659

3760
- Usage:
@@ -44,6 +67,7 @@
4467
- `args_name` must be an array or `_`. If `_`, no arguments will be parsed.
4568
- See test cases for details.
4669
- Dependent: [`start_with`](./condition.md#start_with) [`match`](./string.md#match) [`match_list`](./string.md#match_list)
70+
- Deprecated: true
4771
- Since: 0.4.0
4872
- Bash: 4.0+
4973
- Test Cases: [tests/modules/parse_params.bats](../../tests/modules/parse_params.bats)

docs/module-usages/variable.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- [cur_function_name](#cur_function_name)
88
- [random](#random)
9+
- [var_attrs](#var_attrs)
910
- [xdg_config_home](#xdg_config_home)
1011

1112
## Modules
@@ -32,6 +33,20 @@
3233
- Test Cases: [tests/modules/random.bats](../../tests/modules/random.bats)
3334
- Source Code: [src/modules/random.bash](../../src/modules/random.bash)
3435

36+
### var_attrs
37+
38+
- Usage: `l.var_attrs <var_name>`
39+
- Description:
40+
- Return the attributions of variable.
41+
- If variable undefined, return ''.
42+
- Since: 0.7.0
43+
- Bash: 4.0+
44+
- **Notice**:
45+
- **Only with bash 4.3, this function return 1 when the variable declared without initialization.**
46+
- **Because `declare -p a` shows `declare: a: not found` when `declare -a a`. It's a bug in bash 4.3.**
47+
- Test Cases: [tests/modules/var_attrs.bats](../../tests/modules/var_attrs.bats)
48+
- Source Code: [src/modules/var_attrs.bash](../../src/modules/var_attrs.bash)
49+
3550
### xdg_config_home
3651

3752
- Usage: `l.xdg_config_home`

src/internals/categories/condition

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ has_not.s
77
if
88
is_array
99
is_array.s
10+
is_associative_array
11+
is_associative_array.s
1012
is_bash
1113
is_bash.s
1214
is_dir

src/internals/categories/util

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
benchmark
22
compose
3+
parse_args
34
parse_params
45
repeat
56
sedi

src/internals/categories/variable

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
cur_function_name
22
random
3+
var_attrs
34
xdg_config_home

0 commit comments

Comments
 (0)