From: Alexander Goussas Date: Fri, 31 Oct 2025 23:56:44 +0000 (-0500) Subject: feat: add dockerfile for cli tool to manage squad members X-Git-Url: http://git.frustrated-labs.net/?a=commitdiff_plain;h=0ba97ee17e16455c9cefb7019161b08ab4dcc136;p=squad-rotation-bot.git feat: add dockerfile for cli tool to manage squad members --- diff --git a/cli/Dockerfile b/cli/Dockerfile new file mode 100644 index 0000000..6266de8 --- /dev/null +++ b/cli/Dockerfile @@ -0,0 +1,14 @@ +FROM ubuntu:22.04 + +WORKDIR /app + +RUN apt-get update && apt-get install curl gnupg jq -y + +RUN mkdir -p /etc/apt/keyrings && \ + curl -fsSL https://repo.charm.sh/apt/gpg.key | gpg --dearmor -o /etc/apt/keyrings/charm.gpg && \ + echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | tee /etc/apt/sources.list.d/charm.list && \ + apt update && apt install gum + +COPY ./cli.sh /app/cli.sh + +CMD /app/cli.sh diff --git a/cli/cli.sh b/cli/cli.sh new file mode 100755 index 0000000..60bd1c5 --- /dev/null +++ b/cli/cli.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +API_BASE='http://localhost:3000' + +list_members() { + local members=`curl "$API_BASE/api/v1/rotation/members" 2>/dev/null | jq '.[] | .FullName + "," + .AvatarUrl' | tr -d '"'` + echo "$members" | gum table --columns="Name,Avatar" --separator="," --print +} + +create_member() { + gum style \ + --foreground "#00e0ee" \ + --padding '1 1' \ + --bold \ + "Add a squad member" + + local full_name=`gum input --placeholder 'Full name' --padding '1 1'` + local avatar_url=`gum input --placeholder 'Avatar URL' --padding '1 1'` + + gum style \ + --foreground "#00e0ee" \ + --padding "1 1" \ + "The squad member '$full_name' is going to be created with avatar: '$avatar_url'" + + if gum confirm 'Proceed with creation?'; then + local result=`curl -X POST -i -s "$API_BASE/api/v1/rotation/members" -d "{ \"FullName\": \"$full_name\", \"AvatarUrl\": \"$avatar_url\" }"` + local status_code=`echo $result | head -n1 | cut -d' ' -f2` + if [ "$status_code" = '201' ]; then + gum style --foreground "#00ff00" --bold --padding "1 1" "User created successfully" + else + gum style --foreground "#ff0000" --bold --padding "1 1" "There was an error creating the user" + fi + else + gum style --foreground "#ff0000" --bold --padding "1 1" 'Operation aborted' + fi +} + +read -r -d '' menu_options <<'EOF' +1. List squad members +2. Add squad member +3. Exit +EOF + +while :; do + choice=`echo "$menu_options" | gum choose --header "Menu Options" --padding "1 1" --header.bold | cut -d'.' -f1` + case $choice in + 1) + list_members + ;; + 2) + create_member + ;; + 3) + exit 0 + ;; + esac +done diff --git a/scripts/cli.sh b/scripts/cli.sh deleted file mode 100755 index 60bd1c5..0000000 --- a/scripts/cli.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -API_BASE='http://localhost:3000' - -list_members() { - local members=`curl "$API_BASE/api/v1/rotation/members" 2>/dev/null | jq '.[] | .FullName + "," + .AvatarUrl' | tr -d '"'` - echo "$members" | gum table --columns="Name,Avatar" --separator="," --print -} - -create_member() { - gum style \ - --foreground "#00e0ee" \ - --padding '1 1' \ - --bold \ - "Add a squad member" - - local full_name=`gum input --placeholder 'Full name' --padding '1 1'` - local avatar_url=`gum input --placeholder 'Avatar URL' --padding '1 1'` - - gum style \ - --foreground "#00e0ee" \ - --padding "1 1" \ - "The squad member '$full_name' is going to be created with avatar: '$avatar_url'" - - if gum confirm 'Proceed with creation?'; then - local result=`curl -X POST -i -s "$API_BASE/api/v1/rotation/members" -d "{ \"FullName\": \"$full_name\", \"AvatarUrl\": \"$avatar_url\" }"` - local status_code=`echo $result | head -n1 | cut -d' ' -f2` - if [ "$status_code" = '201' ]; then - gum style --foreground "#00ff00" --bold --padding "1 1" "User created successfully" - else - gum style --foreground "#ff0000" --bold --padding "1 1" "There was an error creating the user" - fi - else - gum style --foreground "#ff0000" --bold --padding "1 1" 'Operation aborted' - fi -} - -read -r -d '' menu_options <<'EOF' -1. List squad members -2. Add squad member -3. Exit -EOF - -while :; do - choice=`echo "$menu_options" | gum choose --header "Menu Options" --padding "1 1" --header.bold | cut -d'.' -f1` - case $choice in - 1) - list_members - ;; - 2) - create_member - ;; - 3) - exit 0 - ;; - esac -done