Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion examples/config-ini/configly
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ config_keys() {
echo "${keys[@]}"
}

# Returns true if the specified key exists in the config file
# Usage:
#
# if config_has_key "key" ; then
# echo "key exists"
# fi
#
config_has_key() {
[[ $(config_get "$1") ]]
}

# :command.command_functions
# :command.function
configly_set_command() {
Expand All @@ -296,7 +307,13 @@ configly_set_command() {
configly_get_command() {
# :src/get_command.sh
# Using the standard library (lib/config.sh) to show a value from the config
config_get "${args[key]}"

key="${args[key]}"
if config_has_key "$key" ; then
config_get "$key"
else
echo "No such key: $key"
fi

# Example of how to assign the config value to a variable:
# result=$(config_get "${args[key]}")
Expand Down
8 changes: 7 additions & 1 deletion examples/config-ini/src/get_command.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Using the standard library (lib/config.sh) to show a value from the config
config_get "${args[key]}"

key="${args[key]}"
if config_has_key "$key" ; then
config_get "$key"
else
echo "No such key: $key"
fi

# Example of how to assign the config value to a variable:
# result=$(config_get "${args[key]}")
Expand Down
11 changes: 11 additions & 0 deletions examples/config-ini/src/lib/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,14 @@ config_keys() {
done < "$CONFIG_FILE"
echo "${keys[@]}"
}

# Returns true if the specified key exists in the config file
# Usage:
#
# if config_has_key "key" ; then
# echo "key exists"
# fi
#
config_has_key() {
[[ $(config_get "$1") ]]
}
1 change: 1 addition & 0 deletions examples/config-ini/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ bashly generate
./configly set hello world
./configly set bashly works
./configly get hello
./configly get invalid_key
./configly list
11 changes: 11 additions & 0 deletions lib/bashly/templates/lib/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,14 @@ config_keys() {
done < "$CONFIG_FILE"
echo "${keys[@]}"
}

# Returns true if the specified key exists in the config file
# Usage:
#
# if config_has_key "key" ; then
# echo "key exists"
# fi
#
config_has_key() {
[[ $(config_get "$1") ]]
}
2 changes: 2 additions & 0 deletions spec/approvals/examples/config-ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ saved: hello = world
saved: bashly = works
+ ./configly get hello
world
+ ./configly get invalid_key
No such key: invalid_key
+ ./configly list
hello = world
bashly = works
Expand Down