mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Add app helpers to parse plain command output
This commit is contained in:
parent
c9f79f7420
commit
444a02b9f9
2 changed files with 36 additions and 2 deletions
|
@ -1,5 +1,15 @@
|
|||
|
||||
# Check if a user exists
|
||||
#
|
||||
# usage: ynh_user_exists username
|
||||
# | ret: retcode - 0 if user exists, 1 otherwise
|
||||
ynh_user_exists() {
|
||||
sudo yunohost user list --json | grep -q "\"username\": \"${1}\""
|
||||
}
|
||||
}
|
||||
|
||||
# Retrieve a user information
|
||||
#
|
||||
# usage: ynh_user_info username key
|
||||
# | ret: string - the key's value
|
||||
ynh_user_get_info() {
|
||||
sudo yunohost user info "${1}" --plain | ynh_get_plain_key "${2}"
|
||||
}
|
||||
|
|
24
data/apps/helpers.d/utils
Normal file
24
data/apps/helpers.d/utils
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Extract a key from a plain command output
|
||||
#
|
||||
# usage: ynh_get_plain_key key [subkey [subsubkey ...]]
|
||||
# | ret: string - the key's value
|
||||
ynh_get_plain_key() {
|
||||
prefix="#"
|
||||
founded=0
|
||||
key=$1
|
||||
shift
|
||||
while read line; do
|
||||
if [[ "$founded" == "1" ]] ; then
|
||||
[[ "$line" =~ ^${prefix}[^#] ]] && return
|
||||
echo $line
|
||||
elif [[ "$line" =~ ^${prefix}${key}$ ]]; then
|
||||
if [[ -n "$1" ]]; then
|
||||
prefix+="#"
|
||||
key=$1
|
||||
shift
|
||||
else
|
||||
founded=1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
Loading…
Add table
Reference in a new issue