From 08edf77dbc313953db4756f2f3c513a927db671e Mon Sep 17 00:00:00 2001 From: Mark Gaballa Date: Sat, 3 Jan 2026 21:26:02 -0800 Subject: [PATCH 1/4] Shell autocomplete --- .envrc | 4 ++++ Makefile | 3 +++ internal/cli/root.go | 19 ++++++++++++++++--- nix/shell.nix | 21 ++++++++++++++++++++- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/.envrc b/.envrc index 4606812..36c54c7 100644 --- a/.envrc +++ b/.envrc @@ -7,4 +7,8 @@ fi use flake PATH_add bin dotenv ./.env +watch_dir bin +if [ -f ./bin/completion ]; then + source ./bin/completion +fi watch_dir nix diff --git a/Makefile b/Makefile index 7474c2e..1290bfb 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ help: ## Display this help screen @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' +SHELL := /bin/bash BIN_DIR := bin API_NAME := acmcsuf-api CLI_NAME := acmcsuf-cli @@ -31,6 +32,8 @@ build: generate ## Build the api and cli binaries @mkdir -p $(BIN_DIR) go build -ldflags "-X main.Version=$(VERSION)" -o $(BIN_DIR)/$(API_NAME) ./cmd/$(API_NAME) go build -ldflags "-X cli.Version=$(VERSION)" -o $(BIN_DIR)/$(CLI_NAME) ./cmd/$(CLI_NAME) + cd $(BIN_DIR) && ./$(CLI_NAME) completion bash > completion + chmod +x $(BIN_DIR)/completion vet: ## Vet all go files go vet ./... diff --git a/internal/cli/root.go b/internal/cli/root.go index e5b0547..6f93b52 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -26,10 +26,23 @@ const ( var Version = "dev" +var allowedArgs []string = []string{ + "events", + "announcements", + "officers", + "config", + "help", + "--help", + "--host", + "--port", + "--version", +} + var rootCmd = &cobra.Command{ - Use: os.Args[0], - Short: "A CLI tool to help manage the API of the CSUF ACM website", - Version: Version, + Use: os.Args[0], + Short: "A CLI tool to help manage the API of the CSUF ACM website", + Version: Version, + ValidArgs: allowedArgs, } // init() is a special function that always gets run before main diff --git a/nix/shell.nix b/nix/shell.nix index 82165a2..8cd9e59 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -13,6 +13,8 @@ go-swag, cobra-cli, go-tools, + bash, + bash-completion, }: mkShell { packages = [ @@ -29,9 +31,26 @@ mkShell { jq go-swag cobra-cli - ]; + bash + bash-completion + ]; shellHook = '' + # Shell auto complete + source ${bash-completion}/etc/profile.d/bash_completion.sh + + if [ ! -d bin ]; then + mkdir bin # Nix blows up if bin isnt here + fi + + COMPLETION_FILE=./bin/completion + if [ -f "$COMPLETION_FILE" ]; then + source "$COMPLETION_FILE" + else + echo "Note: Your cli has no autocomplete, remember to source completion in ./bin or restart the shell when it is generated!" + fi + + export CGO_ENABLED=0 # cgo compiler flags cause issues with delve when using Nix if [ ! -f .env ]; then echo ".env file not found! Creating one from .env.example for you..." From a246b38d2265bf6b09a761467eb1d3efb56719ef Mon Sep 17 00:00:00 2001 From: Mark Gaballa Date: Sat, 3 Jan 2026 21:42:42 -0800 Subject: [PATCH 2/4] Remove valid args --- internal/cli/root.go | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/internal/cli/root.go b/internal/cli/root.go index 6f93b52..e5b0547 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -26,23 +26,10 @@ const ( var Version = "dev" -var allowedArgs []string = []string{ - "events", - "announcements", - "officers", - "config", - "help", - "--help", - "--host", - "--port", - "--version", -} - var rootCmd = &cobra.Command{ - Use: os.Args[0], - Short: "A CLI tool to help manage the API of the CSUF ACM website", - Version: Version, - ValidArgs: allowedArgs, + Use: os.Args[0], + Short: "A CLI tool to help manage the API of the CSUF ACM website", + Version: Version, } // init() is a special function that always gets run before main From ad74611e197fcbaecf607850ad95ea7f6d1f98dc Mon Sep 17 00:00:00 2001 From: Mark Gaballa Date: Sat, 3 Jan 2026 21:49:16 -0800 Subject: [PATCH 3/4] remove redundant source in envrc --- .envrc | 3 --- 1 file changed, 3 deletions(-) diff --git a/.envrc b/.envrc index 36c54c7..609aa49 100644 --- a/.envrc +++ b/.envrc @@ -8,7 +8,4 @@ use flake PATH_add bin dotenv ./.env watch_dir bin -if [ -f ./bin/completion ]; then - source ./bin/completion -fi watch_dir nix From b64d039ede778ae337b5ca1287564770d179583c Mon Sep 17 00:00:00 2001 From: Gaballa <123525159+GaballaGit@users.noreply.github.com> Date: Sat, 3 Jan 2026 22:35:19 -0800 Subject: [PATCH 4/4] okay, maybe sourcing in envrc wasnt redundent c: --- .envrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.envrc b/.envrc index 609aa49..574ad12 100644 --- a/.envrc +++ b/.envrc @@ -7,5 +7,8 @@ fi use flake PATH_add bin dotenv ./.env +if [ -f ./bin/completion ]; then + source ./bin/completion +fi watch_dir bin watch_dir nix