@@ -13,7 +13,9 @@ $ bashly generate
1313$ bashly generate
1414```
1515
16- Running the ` bashly add config ` command simply added the [ src/lib/config.sh] ( src/lib/config.sh ) file, which includes functions for reading and writing values from an INI file.
16+ Running the ` bashly add config ` command simply added the
17+ [ src/lib/config.sh] ( src/lib/config.sh ) file, which includes functions for
18+ reading and writing values from an INI file.
1719
1820See the files in the [ src] ( src ) folder for usage examples.
1921
@@ -29,6 +31,23 @@ help: Sample application that uses the config functions
2931version : 0.1.0
3032
3133commands :
34+ - name : list
35+ alias : l
36+ help : Show the entire config file
37+
38+ - name : get
39+ alias : g
40+ help : Read a value from the config file
41+
42+ args :
43+ - name : key
44+ required : true
45+ help : Config key
46+
47+ examples :
48+ - configly get hello
49+ - configly get user.name
50+
3251- name : set
3352 alias : s
3453 help : Save a value in the config file
@@ -43,72 +62,81 @@ commands:
4362
4463 examples :
4564 - configly set hello world
65+ -
configly set user.email [email protected] 4666
47- - name : get
48- alias : g
49- help : Read a value from the config file
67+ - name : del
68+ alias : d
69+ help : Remove a value from the config file
5070
5171 args :
5272 - name : key
5373 required : true
5474 help : Config key
5575
5676 examples :
57- - configly set hello
58-
59- - name : list
60- alias : l
61- help : Show the entire config file
77+ - configly del hello
78+ - configly del user.name
6279` ` `
6380
6481## ` config.ini`
6582
6683` ` ` ini
67- ; comments are allowed
84+ ; comments are allowed, sections are optional
6885hello = world
6986bashly = works
7087
88+ [options]
89+ name = value for options.name
90+ path = value for options.path
91+
92+ [user]
93+ name = value for user.name
94+ email = value for user.email
7195
7296` ` `
7397
7498# # `src/get_command.sh`
7599
76100` ` ` bash
77101# Using the standard library (lib/config.sh) to show a value from the config
102+ config_load config.ini
78103
79104key="${args[key]}"
80- if config_has_key "$key"; then
81- config_get "$key"
105+ value=${config[$key]}
106+
107+ if [[ "$value" ]]; then
108+ echo "$key = $value"
82109else
83110 echo "No such key: $key"
84111fi
85112
86- # Example of how to assign the config value to a variable:
87- # result=$(config_get "${args[key]}")
88- # echo $result
89-
90-
91113` ` `
92114
93115# # `src/list_command.sh`
94116
95117` ` ` bash
96118# Using the standard library (lib/config.sh) to show the entire config file
119+ config_load config.ini
97120config_show
98121
99- # Or to iterate through keys
100- for key in $(config_keys); do
101- echo "$key === $(config_get "$key")"
102- done
103-
122+ ## Or to iterate through keys manually
123+ # for key in $(config_keys); do
124+ # echo "$key = ${config[$key]}"
125+ # done
104126` ` `
105127
106128# # `src/set_command.sh`
107129
108130` ` ` bash
109131# Using the standard library (lib/config.sh) to store a value to the config
110- config_set "${args[key]}" "${args[value]}"
111- echo "saved: ${args[key]} = ${args[value]}"
132+ config_load config.ini
133+
134+ key="${args[key]}"
135+ value="${args[value]}"
136+
137+ config["$key"]="$value"
138+ config_save saved.ini
139+ cat saved.ini
112140
113141` ` `
114142
@@ -126,9 +154,10 @@ Usage:
126154 configly --version | -v
127155
128156Commands:
129- set Save a value in the config file
130- get Read a value from the config file
131157 list Show the entire config file
158+ get Read a value from the config file
159+ set Save a value in the config file
160+ del Remove a value from the config file
132161
133162Options:
134163 --help, -h
@@ -141,26 +170,52 @@ Options:
141170
142171` ` `
143172
144- # ## `$ ./configly set hello world `
173+ # ## `$ ./configly set hello WORLD `
145174
146175` ` ` shell
147- saved: hello = world
176+ bashly = works
177+ hello = WORLD
178+
179+ [options]
180+ name = value for options.name
181+ path = value for options.path
182+
183+ [user]
184+ email = value for user.email
185+ name = value for user.name
148186
149187
150188` ` `
151189
152- # ## `$ ./configly set bashly works `
190+ # ## `$ ./configly set user.name Megatron `
153191
154192` ` ` shell
155- saved: bashly = works
193+ bashly = works
194+ hello = world
195+
196+ [options]
197+ name = value for options.name
198+ path = value for options.path
199+
200+ [user]
201+ email = value for user.email
202+ name = Megatron
156203
157204
158205` ` `
159206
160207# ## `$ ./configly get hello`
161208
162209` ` ` shell
163- world
210+ hello = world
211+
212+
213+ ` ` `
214+
215+ # ## `$ ./configly get user.name`
216+
217+ ` ` ` shell
218+ user.name = value for user.name
164219
165220
166221` ` `
@@ -173,15 +228,31 @@ No such key: invalid_key
173228
174229` ` `
175230
176- # ## `$ ./configly list `
231+ # ## `$ ./configly del user.email `
177232
178233` ` ` shell
179- ; comments are allowed
180- hello = world
181234bashly = works
235+ hello = world
236+
237+ [options]
238+ name = value for options.name
239+ path = value for options.path
240+
241+ [user]
242+ name = value for user.name
243+
182244
183- hello === world
184- bashly === works
245+ ` ` `
246+
247+ # ## `$ ./configly list`
248+
249+ ` ` ` shell
250+ bashly = works
251+ hello = world
252+ options.name = value for options.name
253+ options.path = value for options.path
254+ user.email = value for user.email
255+ user.name = value for user.name
185256
186257
187258` ` `
0 commit comments