]> git.frustrated-labs.net Git - squad-rotation-bot.git/commitdiff
feat: add CLI tool to manage squad members
authorAlexander Goussas <[email protected]>
Fri, 31 Oct 2025 23:44:59 +0000 (18:44 -0500)
committerAlexander Goussas <[email protected]>
Sun, 2 Nov 2025 00:42:31 +0000 (19:42 -0500)
docker-compose.yaml
scripts/cli.sh [new file with mode: 0755]

index f2f5502af46b8da99332e3aebb9af62442c13db4..2557a2452a0badb1fc278700a35bf4838cf847dd 100644 (file)
@@ -2,6 +2,7 @@ services:
   bot:
     image: "aloussase69/squad-rotation-bot"
     container_name: squad-rotation-bot
+    restart: unless-stopped
     build:
       context: .
     environment:
diff --git a/scripts/cli.sh b/scripts/cli.sh
new file mode 100755 (executable)
index 0000000..60bd1c5
--- /dev/null
@@ -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