refactor(cli): use config.getWebSocketUrl() helper across all commands

Replace inline WebSocket URL construction with Config.getWebSocketUrl()
helper method in all command files. This eliminates code duplication
and ensures consistent URL formatting across the CLI.

Files updated:
- annotate.zig, dataset.zig, experiment.zig, logs.zig
- narrative.zig, prune.zig, queue.zig, requeue.zig
- sync.zig, validate.zig, watch.zig

The helper properly handles ws:// vs wss:// based on port (443).
This commit is contained in:
Jeremie Fraeys 2026-02-18 13:05:43 -05:00
parent c85575048f
commit 34186675dc
No known key found for this signature in database
11 changed files with 16 additions and 16 deletions

View file

@ -92,7 +92,7 @@ pub fn run(allocator: std.mem.Allocator, args: []const []const u8) !void {
const api_key_hash = try crypto.hashApiKey(allocator, cfg.api_key);
defer allocator.free(api_key_hash);
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{cfg.worker_host});
const ws_url = try cfg.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, cfg.api_key);

View file

@ -116,7 +116,7 @@ fn listDatasets(allocator: std.mem.Allocator, options: *const DatasetOptions) !v
return;
}
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{config.worker_host});
const ws_url = try config.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, config.api_key);
@ -214,7 +214,7 @@ fn registerDataset(allocator: std.mem.Allocator, name: []const u8, url: []const
return;
}
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{config.worker_host});
const ws_url = try config.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, config.api_key);
@ -279,7 +279,7 @@ fn showDatasetInfo(allocator: std.mem.Allocator, name: []const u8, options: *con
return;
}
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{config.worker_host});
const ws_url = try config.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, config.api_key);
@ -332,7 +332,7 @@ fn searchDatasets(allocator: std.mem.Allocator, term: []const u8, options: *cons
return;
}
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{config.worker_host});
const ws_url = try config.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, config.api_key);

View file

@ -205,7 +205,7 @@ fn executeLog(allocator: std.mem.Allocator, args: []const []const u8, options: *
const api_key_hash = try crypto.hashApiKey(allocator, cfg.api_key);
defer allocator.free(api_key_hash);
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{cfg.worker_host});
const ws_url = try cfg.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, cfg.api_key);
@ -278,7 +278,7 @@ fn executeShow(allocator: std.mem.Allocator, args: []const []const u8, options:
const api_key_hash = try crypto.hashApiKey(allocator, cfg.api_key);
defer allocator.free(api_key_hash);
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{cfg.worker_host});
const ws_url = try cfg.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, cfg.api_key);
@ -519,7 +519,7 @@ fn executeDelete(allocator: std.mem.Allocator, identifier: []const u8, options:
const api_key_hash = try crypto.hashApiKey(allocator, cfg.api_key);
defer allocator.free(api_key_hash);
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{cfg.worker_host});
const ws_url = try cfg.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, cfg.api_key);

View file

@ -50,7 +50,7 @@ pub fn run(allocator: std.mem.Allocator, argv: []const []const u8) !void {
const api_key_hash = try crypto.hashApiKey(allocator, cfg.api_key);
defer allocator.free(api_key_hash);
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{cfg.worker_host});
const ws_url = try cfg.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, cfg.api_key);

View file

@ -127,7 +127,7 @@ pub fn run(allocator: std.mem.Allocator, argv: []const []const u8) !void {
const api_key_hash = try crypto.hashApiKey(allocator, cfg.api_key);
defer allocator.free(api_key_hash);
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{cfg.worker_host});
const ws_url = try cfg.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, cfg.api_key);

View file

@ -60,7 +60,7 @@ pub fn run(allocator: std.mem.Allocator, args: []const []const u8) !void {
defer allocator.free(api_key_hash);
// Connect to WebSocket and send prune message
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{config.worker_host});
const ws_url = try config.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, api_key_plain);

View file

@ -392,7 +392,7 @@ fn queueSingleJob(
defer allocator.free(api_key_hash);
// Connect to WebSocket and send queue message
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{config.worker_host});
const ws_url = try config.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, config.api_key);

View file

@ -173,7 +173,7 @@ pub fn run(allocator: std.mem.Allocator, argv: []const []const u8) !void {
const api_key_hash = try crypto.hashApiKey(allocator, cfg.api_key);
defer allocator.free(api_key_hash);
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{cfg.worker_host});
const ws_url = try cfg.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, cfg.api_key);

View file

@ -150,7 +150,7 @@ fn monitorSyncProgress(allocator: std.mem.Allocator, config: *const Config, comm
const api_key_plain = config.api_key;
// Connect to server with retry logic
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{config.worker_host});
const ws_url = try config.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
logging.info("Connecting to server {s}...\n", .{ws_url});

View file

@ -51,7 +51,7 @@ pub fn run(allocator: std.mem.Allocator, args: []const []const u8) !void {
if (config.api_key.len == 0) return error.APIKeyMissing;
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{config.worker_host});
const ws_url = try config.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, config.api_key);

View file

@ -124,7 +124,7 @@ fn syncAndQueue(allocator: std.mem.Allocator, path: []const u8, job_name: ?[]con
defer allocator.free(api_key_hash);
// Connect to WebSocket and queue job
const ws_url = try std.fmt.allocPrint(allocator, "ws://{s}:9101/ws", .{config.worker_host});
const ws_url = try config.getWebSocketUrl(allocator);
defer allocator.free(ws_url);
var client = try ws.Client.connect(allocator, ws_url, config.api_key);