Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
3 changes: 2 additions & 1 deletion src/godon/breeder.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions src/godon/client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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": [...]}
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions src/godon_cli.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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] = @[]

Expand Down Expand Up @@ -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)")
Expand All @@ -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
Expand Down Expand Up @@ -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":
Expand Down