File tree Expand file tree Collapse file tree 4 files changed +14
-7
lines changed
lib/bashly/libraries/config Expand file tree Collapse file tree 4 files changed +14
-7
lines changed Original file line number Diff line number Diff line change 77 echo " No such key: $key "
88fi
99
10- # Example of how to assign the config value to a variable:
11- # result=$(config_get "${args[key]}")
12- # echo $result
10+ # Or, assign a default value if value not found
11+ config_get " $key " " the default value"
12+
13+ # Or, assign the result to a variable
14+ result=$( config_get " $key " )
15+ echo $result
1316
Original file line number Diff line number Diff line change @@ -17,11 +17,11 @@ config_init() {
1717}
1818
1919# # Get a value from the config.
20- # # Usage: result=$(config_get hello )
20+ # # Usage: result=$(config_get key) -or- result=$(config_get key "default value" )
2121config_get () {
2222 local key=$1
23+ local value=$2
2324 local regex=" ^$key *= *(.+)$"
24- local value=" "
2525
2626 config_init
2727
Original file line number Diff line number Diff line change @@ -17,11 +17,11 @@ config_init() {
1717}
1818
1919# # Get a value from the config.
20- # # Usage: result=$(config_get hello )
20+ # # Usage: result=$(config_get key) -or- result=$(config_get key "default value" )
2121config_get () {
2222 local key=$1
23+ local value=$2
2324 local regex=" ^$key *= *(.+)$"
24- local value=" "
2525
2626 config_init
2727
Original file line number Diff line number Diff line change @@ -33,8 +33,12 @@ saved: hello = world
3333saved: bashly = works
3434+ ./configly get hello
3535world
36+ world
37+ world
3638+ ./configly get invalid_key
3739No such key: invalid_key
40+ the default value
41+
3842+ ./configly list
3943; comments are allowed
4044hello = world
You can’t perform that action at this time.
0 commit comments