11# Config Example
22
3- Demonstrates how to add functions for reading and writing INI-like files with
4- ` key = value ` pairs.
3+ Demonstrates how to add functions for reading and writing INI configuration
4+ files.
5+
6+ Note that this library uses the [ ini library] ( https://github.com/DannyBen/bashly/tree/master/examples/ini#readme )
7+ for its low-level INI read/write functions.
58
69This example was generated with:
710
@@ -18,7 +21,7 @@ Running the `bashly add config` command simply added the [src/lib/config.sh](src
1821
1922See the files in the [ src] ( src ) folder for usage examples.
2023
21- <!-- include: config.ini src/get_command.sh src/list_command.sh src/set_command.sh -->
24+ <!-- include: config.ini src/get_command.sh src/list_command.sh src/set_command.sh src/del_command.sh -->
2225
2326-----
2427
@@ -44,6 +47,7 @@ commands:
4447
4548 examples :
4649 - configly set hello world
50+ - configly set login.name Megatron
4751
4852- name : get
4953 alias : g
@@ -55,20 +59,35 @@ commands:
5559 help : Config key
5660
5761 examples :
58- - configly set hello
62+ - configly get hello
63+ - configly get login.name
64+
65+ - name : del
66+ alias : d
67+ help : Delete a value from the config file
68+
69+ args :
70+ - name : key
71+ required : true
72+ help : Config key
73+
74+ examples :
75+ - configly del hello
76+ - configly del login.name
5977
6078- name : list
6179 alias : l
62- help : Show the entire config file
80+ help : Show all values
6381` ` `
6482
6583## ` config.ini`
6684
6785` ` ` ini
68- ; comments are allowed
69- hello = world
70- bashly = works
86+ theme = dark
7187
88+ [user]
89+ email = paul@section.one
90+ name = Operations
7291
7392` ` `
7493
@@ -112,7 +131,18 @@ done
112131` ` ` bash
113132# Using the standard library (lib/config.sh) to store a value to the config
114133config_set "${args[key]}" "${args[value]}"
115- echo "saved: ${args[key]} = ${args[value]}"
134+ config_show
135+
136+ ` ` `
137+
138+ # # `src/del_command.sh`
139+
140+ ` ` ` bash
141+ # Using the standard library (lib/config.sh) to delete a value from the config
142+
143+ key="${args[key]}"
144+ config_del "$key"
145+ config_show
116146
117147` ` `
118148
@@ -132,7 +162,8 @@ Usage:
132162Commands:
133163 set Save a value in the config file
134164 get Read a value from the config file
135- list Show the entire config file
165+ del Delete a value from the config file
166+ list Show all values
136167
137168Options:
138169 --help, -h
@@ -145,28 +176,63 @@ Options:
145176
146177` ` `
147178
148- # ## `$ ./configly set hello world `
179+ # ## `$ ./configly set theme dark `
149180
150181` ` ` shell
151- saved: hello = world
182+ theme = dark
183+ user.email = paul@section.one
184+ user.name = Operations
152185
153186
154187` ` `
155188
156- # ## `$ ./configly set bashly works `
189+ # ## `$ ./configly set user.name Operations `
157190
158191` ` ` shell
159- saved: bashly = works
192+ theme = dark
193+ user.email = paul@section.one
194+ user.name = Operations
160195
161196
162197` ` `
163198
164- # ## `$ ./configly get hello `
199+ # ## `$ ./configly set user.email paul@section.one `
165200
166201` ` ` shell
167- world
168- world
169- world
202+ theme = dark
203+ user.email = paul@section.one
204+ user.name = Operations
205+
206+
207+ ` ` `
208+
209+ # ## `$ ./configly set user.password s3cr3t`
210+
211+ ` ` ` shell
212+ theme = dark
213+ user.email = paul@section.one
214+ user.name = Operations
215+ user.password = s3cr3t
216+
217+
218+ ` ` `
219+
220+ # ## `$ ./configly get theme`
221+
222+ ` ` ` shell
223+ dark
224+ dark
225+ dark
226+
227+
228+ ` ` `
229+
230+ # ## `$ ./configly get user.name`
231+
232+ ` ` ` shell
233+ Operations
234+ Operations
235+ Operations
170236
171237
172238` ` `
@@ -181,15 +247,25 @@ the default value
181247
182248` ` `
183249
184- # ## `$ ./configly list `
250+ # ## `$ ./configly del user.password `
185251
186252` ` ` shell
187- ; comments are allowed
188- hello = world
189- bashly = works
253+ theme = dark
254+ user.email = paul@section.one
255+ user.name = Operations
256+
190257
191- hello === world
192- bashly === works
258+ ` ` `
259+
260+ # ## `$ ./configly list`
261+
262+ ` ` ` shell
263+ theme = dark
264+ user.email = paul@section.one
265+ user.name = Operations
266+ theme === dark
267+ user.email === paul@section.one
268+ user.name === Operations
193269
194270
195271` ` `
0 commit comments