Skip to content

Commit 1669a24

Browse files
committed
add debug parameter for cli
1 parent 16acfdd commit 1669a24

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ jobs:
297297
echo "Testing: help shows credential commands"
298298
$BINARY_PATH --help | grep -q "credential" && echo "✅ Credential commands documented in help" || echo "❌ Credential commands missing from help"
299299
300+
# Test --debug flag
301+
echo "Testing: --debug flag works without breaking logic"
302+
$BINARY_PATH --hostname=localhost --port=4010 --debug breeder list
303+
echo "✅ --debug flag works"
304+
300305
- name: Cleanup Prism container
301306
if: always()
302307
run: |

src/godon/breeder.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ proc createBreeder*(client: GodonClient, request: BreederCreateRequest): ApiResp
2323
"name": request.name,
2424
"config": request.config
2525
}
26-
echo "Sending JSON: ", $jsonData
26+
if client.debug:
27+
echo "Sending JSON: ", $jsonData
2728
client.httpClient.headers = newHttpHeaders({"Content-Type": "application/json"})
2829
let response = client.httpClient.post(url, $jsonData)
2930
result = handleResponse[BreederSummary](client, response)

src/godon/client.nim

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ type
1414
config*: ApiConfig
1515
httpClient*: HttpClient
1616
insecure*: bool
17+
debug*: bool
1718

18-
proc newGodonClient*(hostname: string = DefaultHostname,
19-
port: int = DefaultPort,
19+
proc newGodonClient*(hostname: string = DefaultHostname,
20+
port: int = DefaultPort,
2021
apiVersion: string = DefaultApiVersion,
21-
insecure: bool = false): GodonClient =
22+
insecure: bool = false,
23+
debug: bool = false): GodonClient =
2224
## Create a new Godon API client
2325
let config = ApiConfig(
2426
hostname: hostname,
2527
port: port,
2628
apiVersion: apiVersion
2729
)
28-
30+
2931
# Configure HTTP client with SSL verification settings
3032
var httpClient: HttpClient
3133
if insecure:
@@ -35,7 +37,7 @@ proc newGodonClient*(hostname: string = DefaultHostname,
3537
else:
3638
httpClient = newHttpClient()
3739

38-
GodonClient(config: config, httpClient: httpClient, insecure: insecure)
40+
GodonClient(config: config, httpClient: httpClient, insecure: insecure, debug: debug)
3941

4042
proc baseUrl*(client: GodonClient): string =
4143
## Get the base URL for API requests
@@ -61,7 +63,8 @@ proc handleResponse*[T](client: GodonClient; response: Response): ApiResponse[T]
6163
let statusCode = parseInt(split(response.status, " ")[0])
6264
if statusCode >= 200 and statusCode < 300:
6365
try:
64-
echo "Raw response body: ", response.body
66+
if client.debug:
67+
echo "Raw response body: ", response.body
6568
let jsonData = parseJson(response.body)
6669

6770
# Handle nested response structures like {"breeders": [...]} or {"credentials": [...]}
@@ -90,7 +93,8 @@ proc handleResponse*[T](client: GodonClient; response: Response): ApiResponse[T]
9093
result = ApiResponse[T](success: false, data: default(T), error: "JSON parse error: " & e.msg)
9194
else:
9295
try:
93-
echo "HTTP Error Response Body: ", response.body
96+
if client.debug:
97+
echo "HTTP Error Response Body: ", response.body
9498
let errorJson = parseJson(response.body)
9599
let errorMsg = errorJson{"message"}.getStr("HTTP Error: " & $statusCode)
96100
result = ApiResponse[T](success: false, data: default(T), error: errorMsg)

src/godon_cli.nim

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ proc writeError(message: string) =
4848
stderr.writeLine("Error: " & message)
4949
quit(1)
5050

51-
proc parseArgs(): (string, string, int, string, bool, OutputFormat, seq[string]) =
51+
proc parseArgs(): (string, string, int, string, bool, bool, OutputFormat, seq[string]) =
5252
var command = ""
5353
var hostname = "localhost"
5454
var port = 8080
5555
var apiVersion = "v0"
5656
var insecure = false
57+
var debug = false
5758
var outputFormat = OutputFormat.Text
5859
var args: seq[string] = @[]
5960

@@ -91,6 +92,8 @@ proc parseArgs(): (string, string, int, string, bool, OutputFormat, seq[string])
9192
args.add("--id=" & val)
9293
of "insecure":
9394
insecure = true
95+
of "debug":
96+
debug = true
9497
of "output", "o":
9598
if val.len == 0:
9699
writeError("Output option requires a value (text, json, or yaml)")
@@ -116,7 +119,11 @@ proc parseArgs(): (string, string, int, string, bool, OutputFormat, seq[string])
116119
writeHelp()
117120
quit(0)
118121

119-
(command, hostname, port, apiVersion, insecure, outputFormat, args)
122+
# Also check for DEBUG environment variable
123+
if existsEnv("DEBUG"):
124+
debug = true
125+
126+
(command, hostname, port, apiVersion, insecure, debug, outputFormat, args)
120127

121128
proc formatOutput*[T](data: T, outputFormat: OutputFormat) =
122129
## Format data according to output format preference
@@ -354,9 +361,9 @@ proc handleCredentialCommand(client: GodonClient, command: string, args: seq[str
354361
else:
355362
writeError("Unknown credential command: " & subCommand)
356363

357-
let (command, hostname, port, apiVersion, insecure, outputFormat, args) = parseArgs()
364+
let (command, hostname, port, apiVersion, insecure, debug, outputFormat, args) = parseArgs()
358365

359-
let godonClient = newGodonClient(hostname, port, apiVersion, insecure)
366+
let godonClient = newGodonClient(hostname, port, apiVersion, insecure, debug)
360367

361368
case command:
362369
of "breeder":

0 commit comments

Comments
 (0)