feat: implement user management in just
This commit is contained in:
parent
20423eb0cd
commit
9824616c63
2 changed files with 83 additions and 12 deletions
|
|
@ -26,7 +26,7 @@ def to_cells(sizes): to_cells(sizes; null);
|
||||||
def to_line(left; joiner; right):
|
def to_line(left; joiner; right):
|
||||||
[left, .[1], (.[1:] | map([joiner, .]) ), right] | flatten | join("");
|
[left, .[1], (.[1:] | map([joiner, .]) ), right] | flatten | join("");
|
||||||
|
|
||||||
def to_table(data; header_callback; cell_callback):
|
def create(data; header_callback; cell_callback):
|
||||||
(data[0] | to_entries | map(.key)) as $keys
|
(data[0] | to_entries | map(.key)) as $keys
|
||||||
| ([$keys]) as $header
|
| ([$keys]) as $header
|
||||||
| (data | map(to_entries | map(.value))) as $rows
|
| (data | map(to_entries | map(.value))) as $rows
|
||||||
|
|
@ -55,5 +55,5 @@ def to_table(data; header_callback; cell_callback):
|
||||||
| join("\n")
|
| join("\n")
|
||||||
);
|
);
|
||||||
|
|
||||||
def to_table(data; header_callback): to_table(data; header_callback; null);
|
def create(data; header_callback): create(data; header_callback; null);
|
||||||
def to_table(data): to_table(data; _::style(_::BOLD); null);
|
def create(data): create(data; _::style(_::BOLD); null);
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,16 @@ _default:
|
||||||
|
|
||||||
[script]
|
[script]
|
||||||
list:
|
list:
|
||||||
cd .. && just vars get ulmo zitadel/users \
|
cd .. && just vars get ulmo zitadel/users | jq -r -C '
|
||||||
| jq fromjson \
|
import ".jq/table" as table;
|
||||||
| jq -r -C '
|
import ".jq/format" as f;
|
||||||
include ".jq/table";
|
|
||||||
include ".jq/format";
|
|
||||||
|
|
||||||
to_entries
|
fromjson
|
||||||
|
| to_entries
|
||||||
| sort_by(.key)
|
| sort_by(.key)
|
||||||
| map(
|
| map(
|
||||||
(.key|to_title) + ":\n"
|
(.key|f::to_title) + ":\n"
|
||||||
+ to_table(
|
+ table::create(
|
||||||
.value
|
.value
|
||||||
| to_entries
|
| to_entries
|
||||||
| sort_by(.key)
|
| sort_by(.key)
|
||||||
|
|
@ -24,4 +23,76 @@ list:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
| join("\n\n┄┄┄\n\n")
|
| join("\n\n┄┄┄\n\n")
|
||||||
'
|
';
|
||||||
|
|
||||||
|
[script]
|
||||||
|
add:
|
||||||
|
exec 5>&1
|
||||||
|
|
||||||
|
pad () { [ "$#" -gt 1 ] && [ -n "$2" ] && printf "%$2.${2#-}s" "$1"; }
|
||||||
|
|
||||||
|
input() {
|
||||||
|
local label=$1
|
||||||
|
local value=$2
|
||||||
|
|
||||||
|
local res=$(gum input --header "$label" --value "$value")
|
||||||
|
echo -e "\e[2m$(pad "$label" -11)\e[0m$res" >&5
|
||||||
|
echo $res
|
||||||
|
}
|
||||||
|
|
||||||
|
data=`cd .. && just vars get ulmo zitadel/users | jq 'fromjson'`
|
||||||
|
|
||||||
|
# Gather inputs
|
||||||
|
org=`
|
||||||
|
jq -r 'to_entries | map(.key)[]' <<< "$data" \
|
||||||
|
| gum choose --header 'Which organisation to save to?' --select-if-one
|
||||||
|
`
|
||||||
|
username=`input 'user name' 'new-user'`
|
||||||
|
email=`input 'email' 'new.user@example.com'`
|
||||||
|
first_name=`input 'first name' 'John'`
|
||||||
|
last_name=`input 'last name' 'Doe'`
|
||||||
|
|
||||||
|
user_exists=`jq --arg 'org' "$org" --arg 'username' "$username" '.[$org][$username]? | . != null' <<< "$data"`
|
||||||
|
|
||||||
|
if [ "$user_exists" == "true" ]; then
|
||||||
|
gum confirm 'User already exists, overwrite it?' --padding="1 1" || exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
next=`
|
||||||
|
jq \
|
||||||
|
--arg 'org' "$org" \
|
||||||
|
--arg 'username' "$username" \
|
||||||
|
--arg 'email' "$email" \
|
||||||
|
--arg 'first_name' "$first_name" \
|
||||||
|
--arg 'last_name' "$last_name" \
|
||||||
|
--compact-output \
|
||||||
|
'.[$org] += { $username: { email: $email, firstName: $first_name, lastName: $last_name } }' \
|
||||||
|
<<< $data
|
||||||
|
`
|
||||||
|
|
||||||
|
gum spin --title "saving..." -- echo "$(cd .. && just vars set ulmo 'zitadel/users' "$next")"
|
||||||
|
|
||||||
|
[script]
|
||||||
|
remove:
|
||||||
|
data=`cd .. && just vars get ulmo zitadel/users | jq fromjson`
|
||||||
|
|
||||||
|
# Gather inputs
|
||||||
|
org=`
|
||||||
|
jq -r 'to_entries | map(.key)[]' <<< "$data" \
|
||||||
|
| gum choose --header 'Which organisation?' --select-if-one
|
||||||
|
`
|
||||||
|
user=`
|
||||||
|
jq -r --arg org "$org" '.[$org] | to_entries | map(.key)[]' <<< "$data" \
|
||||||
|
| gum choose --header 'Which user?' --select-if-one
|
||||||
|
`
|
||||||
|
|
||||||
|
next=`
|
||||||
|
jq \
|
||||||
|
--arg 'org' "$org" \
|
||||||
|
--arg 'user' "$user" \
|
||||||
|
--compact-output \
|
||||||
|
'del(.[$org][$user])' \
|
||||||
|
<<< $data
|
||||||
|
`
|
||||||
|
|
||||||
|
gum spin --title "saving..." -- echo "$(cd .. && just vars set ulmo 'zitadel/users' "$next")"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue