refactor(cli): use config.getWebSocketUrl() in jupyter.zig
Replace 6 instances of inline WebSocket URL construction with the config.getWebSocketUrl() helper method. This ensures consistent URL formatting and reduces code duplication. Functions updated: - startJupyter - stopJupyter - removeJupyter - listServices - packageCommands Build verified: zig build --release=fast
This commit is contained in:
parent
f2f645fe21
commit
999af75f39
1 changed files with 6 additions and 40 deletions
|
|
@ -36,12 +36,7 @@ fn restoreJupyter(allocator: std.mem.Allocator, args: []const []const u8) !void
|
||||||
mut_config.deinit(allocator);
|
mut_config.deinit(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
const protocol_str = if (config.worker_port == 443) "wss" else "ws";
|
const url = try config.getWebSocketUrl(allocator);
|
||||||
const url = try std.fmt.allocPrint(allocator, "{s}://{s}:{d}/ws", .{
|
|
||||||
protocol_str,
|
|
||||||
config.worker_host,
|
|
||||||
config.worker_port,
|
|
||||||
});
|
|
||||||
defer allocator.free(url);
|
defer allocator.free(url);
|
||||||
|
|
||||||
var client = ws.Client.connect(allocator, url, config.api_key) catch |err| {
|
var client = ws.Client.connect(allocator, url, config.api_key) catch |err| {
|
||||||
|
|
@ -275,13 +270,7 @@ fn startJupyter(allocator: std.mem.Allocator, args: []const []const u8) !void {
|
||||||
mut_config.deinit(allocator);
|
mut_config.deinit(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build WebSocket URL
|
const url = try config.getWebSocketUrl(allocator);
|
||||||
const protocol_str = if (config.worker_port == 443) "wss" else "ws";
|
|
||||||
const url = try std.fmt.allocPrint(allocator, "{s}://{s}:{d}/ws", .{
|
|
||||||
protocol_str,
|
|
||||||
config.worker_host,
|
|
||||||
config.worker_port,
|
|
||||||
});
|
|
||||||
defer allocator.free(url);
|
defer allocator.free(url);
|
||||||
|
|
||||||
// Connect to WebSocket
|
// Connect to WebSocket
|
||||||
|
|
@ -352,13 +341,7 @@ fn stopJupyter(allocator: std.mem.Allocator, args: []const []const u8) !void {
|
||||||
mut_config.deinit(allocator);
|
mut_config.deinit(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build WebSocket URL
|
const url = try config.getWebSocketUrl(allocator);
|
||||||
const protocol_str = if (config.worker_port == 443) "wss" else "ws";
|
|
||||||
const url = try std.fmt.allocPrint(allocator, "{s}://{s}:{d}/ws", .{
|
|
||||||
protocol_str,
|
|
||||||
config.worker_host,
|
|
||||||
config.worker_port,
|
|
||||||
});
|
|
||||||
defer allocator.free(url);
|
defer allocator.free(url);
|
||||||
|
|
||||||
// Connect to WebSocket
|
// Connect to WebSocket
|
||||||
|
|
@ -463,13 +446,7 @@ fn removeJupyter(allocator: std.mem.Allocator, args: []const []const u8) !void {
|
||||||
mut_config.deinit(allocator);
|
mut_config.deinit(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build WebSocket URL
|
const url = try config.getWebSocketUrl(allocator);
|
||||||
const protocol_str = if (config.worker_port == 443) "wss" else "ws";
|
|
||||||
const url = try std.fmt.allocPrint(allocator, "{s}://{s}:{d}/ws", .{
|
|
||||||
protocol_str,
|
|
||||||
config.worker_host,
|
|
||||||
config.worker_port,
|
|
||||||
});
|
|
||||||
defer allocator.free(url);
|
defer allocator.free(url);
|
||||||
|
|
||||||
// Connect to WebSocket
|
// Connect to WebSocket
|
||||||
|
|
@ -541,13 +518,7 @@ fn listServices(allocator: std.mem.Allocator) !void {
|
||||||
mut_config.deinit(allocator);
|
mut_config.deinit(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build WebSocket URL
|
const url = try config.getWebSocketUrl(allocator);
|
||||||
const protocol_str = if (config.worker_port == 443) "wss" else "ws";
|
|
||||||
const url = try std.fmt.allocPrint(allocator, "{s}://{s}:{d}/ws", .{
|
|
||||||
protocol_str,
|
|
||||||
config.worker_host,
|
|
||||||
config.worker_port,
|
|
||||||
});
|
|
||||||
defer allocator.free(url);
|
defer allocator.free(url);
|
||||||
|
|
||||||
// Connect to WebSocket
|
// Connect to WebSocket
|
||||||
|
|
@ -788,12 +759,7 @@ fn packageCommands(args: []const []const u8) !void {
|
||||||
mut_config.deinit(allocator);
|
mut_config.deinit(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
const protocol_str = if (config.worker_port == 443) "wss" else "ws";
|
const url = try config.getWebSocketUrl(allocator);
|
||||||
const url = try std.fmt.allocPrint(allocator, "{s}://{s}:{d}/ws", .{
|
|
||||||
protocol_str,
|
|
||||||
config.worker_host,
|
|
||||||
config.worker_port,
|
|
||||||
});
|
|
||||||
defer allocator.free(url);
|
defer allocator.free(url);
|
||||||
|
|
||||||
var client = ws.Client.connect(allocator, url, config.api_key) catch |err| {
|
var client = ws.Client.connect(allocator, url, config.api_key) catch |err| {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue