File tree Expand file tree Collapse file tree 6 files changed +50
-2
lines changed Expand file tree Collapse file tree 6 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -283,6 +283,17 @@ config_keys() {
283283 echo " ${keys[@]} "
284284}
285285
286+ # Returns true if the specified key exists in the config file
287+ # Usage:
288+ #
289+ # if config_has_key "key" ; then
290+ # echo "key exists"
291+ # fi
292+ #
293+ config_has_key () {
294+ [[ $( config_get " $1 " ) ]]
295+ }
296+
286297# :command.command_functions
287298# :command.function
288299configly_set_command () {
@@ -296,7 +307,13 @@ configly_set_command() {
296307configly_get_command () {
297308 # :src/get_command.sh
298309 # Using the standard library (lib/config.sh) to show a value from the config
299- config_get " ${args[key]} "
310+
311+ key=" ${args[key]} "
312+ if config_has_key " $key " ; then
313+ config_get " $key "
314+ else
315+ echo " No such key: $key "
316+ fi
300317
301318 # Example of how to assign the config value to a variable:
302319 # result=$(config_get "${args[key]}")
Original file line number Diff line number Diff line change 11# Using the standard library (lib/config.sh) to show a value from the config
2- config_get " ${args[key]} "
2+
3+ key=" ${args[key]} "
4+ if config_has_key " $key " ; then
5+ config_get " $key "
6+ else
7+ echo " No such key: $key "
8+ fi
39
410# Example of how to assign the config value to a variable:
511# result=$(config_get "${args[key]}")
Original file line number Diff line number Diff line change @@ -113,3 +113,14 @@ config_keys() {
113113 done < " $CONFIG_FILE "
114114 echo " ${keys[@]} "
115115}
116+
117+ # Returns true if the specified key exists in the config file
118+ # Usage:
119+ #
120+ # if config_has_key "key" ; then
121+ # echo "key exists"
122+ # fi
123+ #
124+ config_has_key () {
125+ [[ $( config_get " $1 " ) ]]
126+ }
Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ bashly generate
88./configly set hello world
99./configly set bashly works
1010./configly get hello
11+ ./configly get invalid_key
1112./configly list
Original file line number Diff line number Diff line change @@ -113,3 +113,14 @@ config_keys() {
113113 done < " $CONFIG_FILE "
114114 echo " ${keys[@]} "
115115}
116+
117+ # Returns true if the specified key exists in the config file
118+ # Usage:
119+ #
120+ # if config_has_key "key" ; then
121+ # echo "key exists"
122+ # fi
123+ #
124+ config_has_key () {
125+ [[ $( config_get " $1 " ) ]]
126+ }
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ saved: hello = world
3232saved: bashly = works
3333+ ./configly get hello
3434world
35+ + ./configly get invalid_key
36+ No such key: invalid_key
3537+ ./configly list
3638hello = world
3739bashly = works
You can’t perform that action at this time.
0 commit comments