diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2aad3c..43f8106 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -297,6 +297,11 @@ jobs: echo "Testing: help shows credential commands" $BINARY_PATH --help | grep -q "credential" && echo "✅ Credential commands documented in help" || echo "❌ Credential commands missing from help" + # Test --debug flag + echo "Testing: --debug flag works without breaking logic" + $BINARY_PATH --hostname=localhost --port=4010 --debug breeder list + echo "✅ --debug flag works" + - name: Cleanup Prism container if: always() run: | diff --git a/src/godon/breeder.nim b/src/godon/breeder.nim index f02cd51..d35f408 100644 --- a/src/godon/breeder.nim +++ b/src/godon/breeder.nim @@ -23,7 +23,8 @@ proc createBreeder*(client: GodonClient, request: BreederCreateRequest): ApiResp "name": request.name, "config": request.config } - echo "Sending JSON: ", $jsonData + if client.debug: + echo "Sending JSON: ", $jsonData client.httpClient.headers = newHttpHeaders({"Content-Type": "application/json"}) let response = client.httpClient.post(url, $jsonData) result = handleResponse[BreederSummary](client, response) diff --git a/src/godon/client.nim b/src/godon/client.nim index 28cd049..8e79360 100644 --- a/src/godon/client.nim +++ b/src/godon/client.nim @@ -14,18 +14,20 @@ type config*: ApiConfig httpClient*: HttpClient insecure*: bool + debug*: bool -proc newGodonClient*(hostname: string = DefaultHostname, - port: int = DefaultPort, +proc newGodonClient*(hostname: string = DefaultHostname, + port: int = DefaultPort, apiVersion: string = DefaultApiVersion, - insecure: bool = false): GodonClient = + insecure: bool = false, + debug: bool = false): GodonClient = ## Create a new Godon API client let config = ApiConfig( hostname: hostname, port: port, apiVersion: apiVersion ) - + # Configure HTTP client with SSL verification settings var httpClient: HttpClient if insecure: @@ -35,7 +37,7 @@ proc newGodonClient*(hostname: string = DefaultHostname, else: httpClient = newHttpClient() - GodonClient(config: config, httpClient: httpClient, insecure: insecure) + GodonClient(config: config, httpClient: httpClient, insecure: insecure, debug: debug) proc baseUrl*(client: GodonClient): string = ## Get the base URL for API requests @@ -61,7 +63,8 @@ proc handleResponse*[T](client: GodonClient; response: Response): ApiResponse[T] let statusCode = parseInt(split(response.status, " ")[0]) if statusCode >= 200 and statusCode < 300: try: - echo "Raw response body: ", response.body + if client.debug: + echo "Raw response body: ", response.body let jsonData = parseJson(response.body) # Handle nested response structures like {"breeders": [...]} or {"credentials": [...]} @@ -90,7 +93,8 @@ proc handleResponse*[T](client: GodonClient; response: Response): ApiResponse[T] result = ApiResponse[T](success: false, data: default(T), error: "JSON parse error: " & e.msg) else: try: - echo "HTTP Error Response Body: ", response.body + if client.debug: + echo "HTTP Error Response Body: ", response.body let errorJson = parseJson(response.body) let errorMsg = errorJson{"message"}.getStr("HTTP Error: " & $statusCode) result = ApiResponse[T](success: false, data: default(T), error: errorMsg) diff --git a/src/godon_cli.nim b/src/godon_cli.nim index eb7edec..e7eb983 100644 --- a/src/godon_cli.nim +++ b/src/godon_cli.nim @@ -48,12 +48,13 @@ proc writeError(message: string) = stderr.writeLine("Error: " & message) quit(1) -proc parseArgs(): (string, string, int, string, bool, OutputFormat, seq[string]) = +proc parseArgs(): (string, string, int, string, bool, bool, OutputFormat, seq[string]) = var command = "" var hostname = "localhost" var port = 8080 var apiVersion = "v0" var insecure = false + var debug = false var outputFormat = OutputFormat.Text var args: seq[string] = @[] @@ -91,6 +92,8 @@ proc parseArgs(): (string, string, int, string, bool, OutputFormat, seq[string]) args.add("--id=" & val) of "insecure": insecure = true + of "debug": + debug = true of "output", "o": if val.len == 0: writeError("Output option requires a value (text, json, or yaml)") @@ -116,7 +119,11 @@ proc parseArgs(): (string, string, int, string, bool, OutputFormat, seq[string]) writeHelp() quit(0) - (command, hostname, port, apiVersion, insecure, outputFormat, args) + # Also check for DEBUG environment variable + if existsEnv("DEBUG"): + debug = true + + (command, hostname, port, apiVersion, insecure, debug, outputFormat, args) proc formatOutput*[T](data: T, outputFormat: OutputFormat) = ## Format data according to output format preference @@ -354,9 +361,9 @@ proc handleCredentialCommand(client: GodonClient, command: string, args: seq[str else: writeError("Unknown credential command: " & subCommand) -let (command, hostname, port, apiVersion, insecure, outputFormat, args) = parseArgs() +let (command, hostname, port, apiVersion, insecure, debug, outputFormat, args) = parseArgs() -let godonClient = newGodonClient(hostname, port, apiVersion, insecure) +let godonClient = newGodonClient(hostname, port, apiVersion, insecure, debug) case command: of "breeder":