mirror of
https://github.com/mikkelam/fast-cli.git
synced 2025-12-18 12:54:05 +00:00
Clean-up comments
This commit is contained in:
parent
e7e1efbd57
commit
f670606e24
4 changed files with 29 additions and 31 deletions
|
|
@ -4,9 +4,7 @@
|
|||
[](https://github.com/mikkelam/fast-cli-zig/actions/workflows/ci.yml)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
|
||||
A blazingly fast CLI tool for testing internet speed compatible with fast.com (api v2). Written in Zig for maximum performance.
|
||||
|
||||
Uses **Fast.com-style stability detection** by default for accurate results with adaptive stopping.
|
||||
A blazingly fast CLI tool for testing internet speed uses fast.com v2 api. Written in Zig for maximum performance.
|
||||
|
||||
⚡ **1.3 MiB binary** • 🚀 **Zero runtime deps** • 📊 **Smart stability detection**
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ const SpeedTestResult = @import("../lib/http_speed_tester_v2.zig").SpeedTestResu
|
|||
const BandwidthMeter = @import("../lib/bandwidth.zig");
|
||||
const SpeedMeasurement = @import("../lib/bandwidth.zig").SpeedMeasurement;
|
||||
const progress = @import("../lib/progress.zig");
|
||||
const HttpLatencyTester = @import("../lib/latency.zig").HttpLatencyTester;
|
||||
const HttpLatencyTester = @import("../lib/http_latency_tester.zig").HttpLatencyTester;
|
||||
const log = std.log.scoped(.cli);
|
||||
|
||||
/// Update spinner text with current speed measurement
|
||||
|
|
@ -48,7 +48,7 @@ const json_output_flag = zli.Flag{
|
|||
|
||||
const max_duration_flag = zli.Flag{
|
||||
.name = "duration",
|
||||
.description = "Maximum test duration in seconds (uses Fast.com-style stability detection by default)",
|
||||
.description = "Maximum test duration in seconds (uses CoV stability detection by default)",
|
||||
.shortcut = "d",
|
||||
.type = .Int,
|
||||
.default_value = .{ .Int = 30 },
|
||||
|
|
@ -131,7 +131,7 @@ fn run(ctx: zli.CommandContext) !void {
|
|||
|
||||
const download_result = if (json_output) blk: {
|
||||
// JSON mode: clean output only
|
||||
break :blk speed_tester.measure_download_speed_fast_stability(urls, criteria) catch |err| {
|
||||
break :blk speed_tester.measure_download_speed_stability(urls, criteria) catch |err| {
|
||||
log.err("Download test failed: {}", .{err});
|
||||
std.debug.print("{{\"error\": \"{}\"}}\n", .{err});
|
||||
return;
|
||||
|
|
@ -139,7 +139,7 @@ fn run(ctx: zli.CommandContext) !void {
|
|||
} else blk: {
|
||||
// Interactive mode with spinner updates
|
||||
const progressCallback = progress.createCallback(ctx.spinner, updateSpinnerText);
|
||||
break :blk speed_tester.measureDownloadSpeedWithFastStabilityProgress(urls, criteria, progressCallback) catch |err| {
|
||||
break :blk speed_tester.measureDownloadSpeedWithStabilityProgress(urls, criteria, progressCallback) catch |err| {
|
||||
try ctx.spinner.fail("Download test failed: {}", .{err});
|
||||
return;
|
||||
};
|
||||
|
|
@ -153,7 +153,7 @@ fn run(ctx: zli.CommandContext) !void {
|
|||
|
||||
upload_result = if (json_output) blk: {
|
||||
// JSON mode: clean output only
|
||||
break :blk speed_tester.measure_upload_speed_fast_stability(urls, criteria) catch |err| {
|
||||
break :blk speed_tester.measure_upload_speed_stability(urls, criteria) catch |err| {
|
||||
log.err("Upload test failed: {}", .{err});
|
||||
std.debug.print("{{\"error\": \"{}\"}}\n", .{err});
|
||||
return;
|
||||
|
|
@ -161,7 +161,7 @@ fn run(ctx: zli.CommandContext) !void {
|
|||
} else blk: {
|
||||
// Interactive mode with spinner updates
|
||||
const uploadProgressCallback = progress.createCallback(ctx.spinner, updateUploadSpinnerText);
|
||||
break :blk speed_tester.measureUploadSpeedWithFastStabilityProgress(urls, criteria, uploadProgressCallback) catch |err| {
|
||||
break :blk speed_tester.measureUploadSpeedWithStabilityProgress(urls, criteria, uploadProgressCallback) catch |err| {
|
||||
try ctx.spinner.fail("Upload test failed: {}", .{err});
|
||||
return;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -50,32 +50,32 @@ pub const HTTPSpeedTester = struct {
|
|||
_ = self;
|
||||
}
|
||||
|
||||
// Fast.com-style stability-based download with optional progress callback
|
||||
pub fn measure_download_speed_fast_stability_duration(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, comptime ProgressType: ?type, progress_callback: if (ProgressType) |T| T else void) !SpeedTestResult {
|
||||
// Stability-based download with optional progress callback
|
||||
pub fn measure_download_speed_stability_duration(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, comptime ProgressType: ?type, progress_callback: if (ProgressType) |T| T else void) !SpeedTestResult {
|
||||
var strategy = measurement_strategy.createStabilityStrategy(self.allocator, criteria);
|
||||
defer strategy.deinit();
|
||||
return self.measureDownloadSpeedWithFastStability(urls, &strategy, ProgressType, progress_callback);
|
||||
return self.measureDownloadSpeedWithStability(urls, &strategy, ProgressType, progress_callback);
|
||||
}
|
||||
|
||||
// Fast.com-style stability-based download without progress callback
|
||||
pub fn measure_download_speed_fast_stability(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria) !SpeedTestResult {
|
||||
return self.measure_download_speed_fast_stability_duration(urls, criteria, null, {});
|
||||
// Stability-based download without progress callback
|
||||
pub fn measure_download_speed_stability(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria) !SpeedTestResult {
|
||||
return self.measure_download_speed_stability_duration(urls, criteria, null, {});
|
||||
}
|
||||
|
||||
// Fast.com-style stability-based upload with optional progress callback
|
||||
pub fn measure_upload_speed_fast_stability_duration(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, comptime ProgressType: ?type, progress_callback: if (ProgressType) |T| T else void) !SpeedTestResult {
|
||||
// Stability-based upload with optional progress callback
|
||||
pub fn measure_upload_speed_stability_duration(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, comptime ProgressType: ?type, progress_callback: if (ProgressType) |T| T else void) !SpeedTestResult {
|
||||
const upload_data = try self.allocator.alloc(u8, 4 * 1024 * 1024);
|
||||
defer self.allocator.free(upload_data);
|
||||
@memset(upload_data, 'A');
|
||||
|
||||
var strategy = measurement_strategy.createStabilityStrategy(self.allocator, criteria);
|
||||
defer strategy.deinit();
|
||||
return self.measureUploadSpeedWithFastStability(urls, &strategy, upload_data, ProgressType, progress_callback);
|
||||
return self.measureUploadSpeedWithStability(urls, &strategy, upload_data, ProgressType, progress_callback);
|
||||
}
|
||||
|
||||
// Fast.com-style stability-based upload without progress callback
|
||||
pub fn measure_upload_speed_fast_stability(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria) !SpeedTestResult {
|
||||
return self.measure_upload_speed_fast_stability_duration(urls, criteria, null, {});
|
||||
// Stability-based upload without progress callback
|
||||
pub fn measure_upload_speed_stability(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria) !SpeedTestResult {
|
||||
return self.measure_upload_speed_stability_duration(urls, criteria, null, {});
|
||||
}
|
||||
|
||||
// Convenience helpers for cleaner API usage
|
||||
|
|
@ -106,14 +106,14 @@ pub const HTTPSpeedTester = struct {
|
|||
return self.measure_upload_speed_duration(urls, duration_seconds, null, {});
|
||||
}
|
||||
|
||||
/// Fast stability download speed measurement with progress callback (type inferred)
|
||||
pub fn measureDownloadSpeedWithFastStabilityProgress(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, progress_callback: anytype) !SpeedTestResult {
|
||||
return self.measure_download_speed_fast_stability_duration(urls, criteria, @TypeOf(progress_callback), progress_callback);
|
||||
/// Stability-based download speed measurement with progress callback (type inferred)
|
||||
pub fn measureDownloadSpeedWithStabilityProgress(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, progress_callback: anytype) !SpeedTestResult {
|
||||
return self.measure_download_speed_stability_duration(urls, criteria, @TypeOf(progress_callback), progress_callback);
|
||||
}
|
||||
|
||||
/// Fast stability upload speed measurement with progress callback (type inferred)
|
||||
pub fn measureUploadSpeedWithFastStabilityProgress(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, progress_callback: anytype) !SpeedTestResult {
|
||||
return self.measure_upload_speed_fast_stability_duration(urls, criteria, @TypeOf(progress_callback), progress_callback);
|
||||
/// Stability-based upload speed measurement with progress callback (type inferred)
|
||||
pub fn measureUploadSpeedWithStabilityProgress(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, progress_callback: anytype) !SpeedTestResult {
|
||||
return self.measure_upload_speed_stability_duration(urls, criteria, @TypeOf(progress_callback), progress_callback);
|
||||
}
|
||||
|
||||
// Private implementation for duration-based download
|
||||
|
|
@ -248,8 +248,8 @@ pub const HTTPSpeedTester = struct {
|
|||
return SpeedTestResult.fromBytesPerSecond(speed_bytes_per_sec);
|
||||
}
|
||||
|
||||
// Private implementation for Fast.com-style stability-based download
|
||||
fn measureDownloadSpeedWithFastStability(
|
||||
// Private implementation for stability-based download
|
||||
fn measureDownloadSpeedWithStability(
|
||||
self: *HTTPSpeedTester,
|
||||
urls: []const []const u8,
|
||||
strategy: *StabilityStrategy,
|
||||
|
|
@ -320,8 +320,8 @@ pub const HTTPSpeedTester = struct {
|
|||
return SpeedTestResult.fromBytesPerSecond(speed_bytes_per_sec);
|
||||
}
|
||||
|
||||
// Private implementation for Fast.com-style stability-based upload
|
||||
fn measureUploadSpeedWithFastStability(
|
||||
// Private implementation for stability-based upload
|
||||
fn measureUploadSpeedWithStability(
|
||||
self: *HTTPSpeedTester,
|
||||
urls: []const []const u8,
|
||||
strategy: *StabilityStrategy,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue