1
1
# Config Example
2
2
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.
5
8
6
9
This example was generated with:
7
10
@@ -18,7 +21,7 @@ Running the `bashly add config` command simply added the [src/lib/config.sh](src
18
21
19
22
See the files in the [ src] ( src ) folder for usage examples.
20
23
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 -->
22
25
23
26
-----
24
27
@@ -44,6 +47,7 @@ commands:
44
47
45
48
examples :
46
49
- configly set hello world
50
+ - configly set login.name Megatron
47
51
48
52
- name : get
49
53
alias : g
@@ -55,20 +59,35 @@ commands:
55
59
help : Config key
56
60
57
61
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
59
77
60
78
- name : list
61
79
alias : l
62
- help : Show the entire config file
80
+ help : Show all values
63
81
` ` `
64
82
65
83
## ` config.ini`
66
84
67
85
` ` ` ini
68
- ; comments are allowed
69
- hello = world
70
- bashly = works
86
+ theme = dark
71
87
88
+ [user]
89
+ email = paul@section.one
90
+ name = Operations
72
91
73
92
` ` `
74
93
@@ -112,7 +131,18 @@ done
112
131
` ` ` bash
113
132
# Using the standard library (lib/config.sh) to store a value to the config
114
133
config_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
116
146
117
147
` ` `
118
148
@@ -132,7 +162,8 @@ Usage:
132
162
Commands:
133
163
set Save a value in the config file
134
164
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
136
167
137
168
Options:
138
169
--help, -h
@@ -145,28 +176,63 @@ Options:
145
176
146
177
` ` `
147
178
148
- # ## `$ ./configly set hello world `
179
+ # ## `$ ./configly set theme dark `
149
180
150
181
` ` ` shell
151
- saved: hello = world
182
+ theme = dark
183
+ user.email = paul@section.one
184
+ user.name = Operations
152
185
153
186
154
187
` ` `
155
188
156
- # ## `$ ./configly set bashly works `
189
+ # ## `$ ./configly set user.name Operations `
157
190
158
191
` ` ` shell
159
- saved: bashly = works
192
+ theme = dark
193
+ user.email = paul@section.one
194
+ user.name = Operations
160
195
161
196
162
197
` ` `
163
198
164
- # ## `$ ./configly get hello `
199
+ # ## `$ ./configly set user.email paul@section.one `
165
200
166
201
` ` ` 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
170
236
171
237
172
238
` ` `
@@ -181,15 +247,25 @@ the default value
181
247
182
248
` ` `
183
249
184
- # ## `$ ./configly list `
250
+ # ## `$ ./configly del user.password `
185
251
186
252
` ` ` 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
+
190
257
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
193
269
194
270
195
271
` ` `
0 commit comments