tiny.smg.cli.validation
Defined in cli.
API (18)
Actions
Public operations.
choiceListconfiguredLimitsOrRejectnoSuchOptionMessageoptionWithForbiddenValuerejectForbiddenOptionValuesrejectInvalidChoiceOptionrejectInvalidFloatOptionrejectInvalidIntegerOptionrejectInvalidIntegerRangeOptionrejectInvalidLinerejectInvalidMetarejectMissingOptionValuesrejectMissingPathsrejectUnexpectedOptionsrejectUnexpectedOptionsPlainrejectUnexpectedScanOptionsunexpectedArgumentMessagevalidateQueryNameCommand
Source
Source: tools/smg/src/cli/validation/query.zig:11
pub fn validateQueryNameCommand(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, args: []const []const u8, allowed: []const []const u8, formats: []const []const u8) !bool { if (try value.rejectMissingOptionValues(allocator, args, allowed)) return true; if (try unexpected.rejectUnexpectedOptionsPlain(allocator, command, signature, args, allowed)) return true; if (try value.rejectInvalidChoiceOption(allocator, command, signature, args, "--format", formats)) return true; if (list.containsString(allowed, "--depth")) { if (try value.rejectInvalidIntegerOption(allocator, command, signature, args, "--depth")) return true; } if (list.containsString(allowed, "--limit")) { if (try value.rejectInvalidIntegerOption(allocator, command, signature, args, "--limit")) return true; } const pos = try options.positional(allocator, args); if (pos.len == 0) { try output.writeClickUsageError(allocator, command, signature, "Missing argument 'NAME'."); return true; } if (pos.len > 1) { try output.writeClickUsageError(allocator, command, signature, try unexpected.unexpectedArgumentMessage(allocator, pos[1..])); return true; } return false;}Source: tools/smg/src/cli/validation/unexpected.zig:58
pub fn noSuchOptionMessage(allocator: std.mem.Allocator, option: []const u8, candidates: []const []const u8) ![]const u8 { const suggestion = nearestOption(option, candidates); if (suggestion) |candidate| return try std.fmt.allocPrint(allocator, "No such option: {s} Did you mean {s}?", .{ option, candidate }); return try std.fmt.allocPrint(allocator, "No such option: {s}", .{option});}Source: tools/smg/src/cli/validation/unexpected.zig:9
pub fn rejectUnexpectedOptions(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, args: []const []const u8, allowed: []const []const u8) !bool { for (args) |arg| { if (!std.mem.startsWith(u8, arg, "--")) continue; const name = options.optionName(arg); if (list.containsString(allowed, name)) continue; try output.writeClickUsageError(allocator, command, signature, try noSuchOptionMessage(allocator, name, allowed)); return true; } return false;}Source: tools/smg/src/cli/validation/unexpected.zig:20
pub fn rejectUnexpectedOptionsPlain(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, args: []const []const u8, allowed: []const []const u8) !bool { for (args) |arg| { if (!std.mem.startsWith(u8, arg, "--")) continue; const name = options.optionName(arg); if (list.containsString(allowed, name)) continue; try output.writeClickUsageError(allocator, command, signature, try std.fmt.allocPrint(allocator, "No such option: {s}", .{name})); return true; } return false;}Source: tools/smg/src/cli/validation/unexpected.zig:31
pub fn rejectUnexpectedScanOptions(allocator: std.mem.Allocator, args: []const []const u8) !bool { const allowed = [_][]const u8{ "--clean", "--changed", "--since", "--exclude", "--format", "--full", options.max_source_file_bytes_option, options.max_fragment_bytes_option, options.max_git_file_list_bytes_option, options.wal_recovery_limit_bytes_option, }; for (args) |arg| { if (!std.mem.startsWith(u8, arg, "--")) continue; const name = options.optionName(arg); if (list.containsString(&allowed, name)) continue; const message = if (std.mem.eql(u8, name, "--json")) try std.fmt.allocPrint(allocator, "No such option: {s} (Possible options: --since)", .{name}) else try noSuchOptionMessage(allocator, name, &allowed); try output.writeClickUsageError(allocator, "scan", "[OPTIONS] [PATHS]...", message); return true; } return false;}Source: tools/smg/src/cli/validation/unexpected.zig:101
pub fn unexpectedArgumentMessage(allocator: std.mem.Allocator, values: []const []const u8) ![]const u8 { if (values.len == 1) return try std.fmt.allocPrint(allocator, "Got unexpected extra argument ({s})", .{values[0]}); return try std.fmt.allocPrint(allocator, "Got unexpected extra arguments ({s})", .{try list.joinStrings(allocator, values, " ")});}Source: tools/smg/src/cli/validation/value.zig:50
pub fn choiceList(allocator: std.mem.Allocator, choices: []const []const u8) ![]const u8 { var out: std.Io.Writer.Allocating = .init(allocator); for (choices, 0..) |choice, index| { if (index != 0) try out.writer.writeAll(", "); try out.writer.print("'{s}'", .{choice}); } return out.written();}Source: tools/smg/src/cli/validation/value.zig:77
pub fn configuredLimitsOrReject( allocator: std.mem.Allocator, command: []const u8, signature: []const u8, args: []const []const u8, base: smg.Limits,) !?smg.Limits { switch (options.configuredLimits(args, base)) { .limits => |limits| return limits, .invalid => |failure| { const message = switch (failure.reason) { .invalid_size => try std.fmt.allocPrint( allocator, "Invalid value for '{s}': '{s}'. Use a positive byte size such as 32MiB.", .{ failure.option, failure.value }, ), .capacity_overflow => try std.fmt.allocPrint( allocator, "Invalid value for '{s}': '{s}' exceeds this platform's capacity.", .{ failure.option, failure.value }, ), .fragment_header => try std.fmt.allocPrint( allocator, "Invalid value for '{s}': '{s}' cannot hold the fragment header.", .{ failure.option, failure.value }, ), }; try output.writeClickUsageError(allocator, command, signature, message); return null; }, }}Source: tools/smg/src/cli/validation/value.zig:34
pub fn optionWithForbiddenValue(args: []const []const u8, forbidden: []const []const u8) ?[]const u8 { for (args) |arg| { const name = options.optionName(arg); if (!list.containsString(forbidden, name)) continue; if (options.inlineOptionValue(arg) != null) return name; } return null;}Source: tools/smg/src/cli/validation/value.zig:26
pub fn rejectForbiddenOptionValues(allocator: std.mem.Allocator, args: []const []const u8, forbidden: []const []const u8) !bool { if (optionWithForbiddenValue(args, forbidden)) |option| { try output.writeClickBoxError(allocator, try std.fmt.allocPrint(allocator, "Option '{s}' does not take a value.", .{option})); return true; } return false;}Source: tools/smg/src/cli/validation/value.zig:43
pub fn rejectInvalidChoiceOption(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, args: []const []const u8, option: []const u8, choices: []const []const u8) !bool { const raw = options.flagValue(args, option) orelse return false; if (list.containsString(choices, raw)) return false; try output.writeClickUsageError(allocator, command, signature, try std.fmt.allocPrint(allocator, "Invalid value for '{s}': '{s}' is not one of {s}.", .{ option, raw, try choiceList(allocator, choices) })); return true;}Source: tools/smg/src/cli/validation/value.zig:68
pub fn rejectInvalidFloatOption(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, args: []const []const u8, option: []const u8) !bool { const raw = options.flagValue(args, option) orelse return false; _ = std.fmt.parseFloat(f64, raw) catch { try output.writeClickUsageError(allocator, command, signature, try std.fmt.allocPrint(allocator, "Invalid value for '{s}': '{s}' is not a valid float.", .{ option, raw })); return true; }; return false;}Source: tools/smg/src/cli/validation/value.zig:59
pub fn rejectInvalidIntegerOption(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, args: []const []const u8, option: []const u8) !bool { const raw = options.flagValue(args, option) orelse return false; _ = std.fmt.parseInt(i64, raw, 10) catch { try output.writeClickUsageError(allocator, command, signature, try std.fmt.allocPrint(allocator, "Invalid value for '{s}': '{s}' is not a valid integer.", .{ option, raw })); return true; }; return false;}Source: tools/smg/src/cli/validation/value.zig:119
pub fn rejectInvalidIntegerRangeOption(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, args: []const []const u8, option: []const u8, minimum: i64, maximum: i64) !bool { const raw = options.flagValue(args, option) orelse return false; const value = std.fmt.parseInt(i64, raw, 10) catch { try output.writeClickUsageError(allocator, command, signature, try std.fmt.allocPrint(allocator, "Invalid value for '{s}': '{s}' is not a valid integer.", .{ option, raw })); return true; }; if (value >= minimum and value <= maximum) return false; try output.writeClickUsageError(allocator, command, signature, try std.fmt.allocPrint(allocator, "Invalid value for '{s}': {d} is not in the range {d}<=x<={d}.", .{ option, value, minimum, maximum })); return true;}Source: tools/smg/src/cli/validation/value.zig:130
pub fn rejectInvalidLine(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, args: []const []const u8) !bool { if (options.flagValue(args, "--line")) |raw| { _ = std.fmt.parseInt(i64, raw, 10) catch { try output.writeClickUsageError(allocator, command, signature, try std.fmt.allocPrint(allocator, "Invalid value for '--line': '{s}' is not a valid integer.", .{raw})); return true; }; } return false;}Source: tools/smg/src/cli/validation/value.zig:140
pub fn rejectInvalidMeta(allocator: std.mem.Allocator, args: []const []const u8) !bool { var i: usize = 0; while (i + 1 < args.len) : (i += 1) { if (!std.mem.eql(u8, args[i], "--meta")) continue; const raw = args[i + 1]; if (std.mem.indexOfScalar(u8, raw, '=') == null) { try output.writeErrFmt(allocator, "Error: --meta must be KEY=VALUE, got '{s}'\n", .{raw}); return true; } i += 1; } return false;}Source: tools/smg/src/cli/validation/value.zig:11
pub fn rejectMissingOptionValues(allocator: std.mem.Allocator, args: []const []const u8, allowed: []const []const u8) !bool { var i: usize = 0; while (i < args.len) : (i += 1) { const arg = args[i]; if (!list.containsString(allowed, options.optionName(arg))) continue; if (options.inlineOptionValue(arg) != null) continue; if (i + 1 == args.len or std.mem.startsWith(u8, args[i + 1], "--")) { try output.writeClickBoxError(allocator, try std.fmt.allocPrint(allocator, "Option '{s}' requires an argument.", .{options.optionName(arg)})); return true; } i += 1; } return false;}Source: tools/smg/src/cli/validation/value.zig:110
pub fn rejectMissingPaths(allocator: std.mem.Allocator, command: []const u8, signature: []const u8, paths: []const []const u8) !bool { for (paths) |path| { if (sys.fs.exists(path)) continue; try output.writeClickUsageError(allocator, command, signature, try std.fmt.allocPrint(allocator, "Invalid value for '[PATHS]...': Path '{s}' does not exist.", .{path})); return true; } return false;}Source: tools/smg/src/cli/root.zig:11
pub const validation = @import("validation/root.zig");Source: tools/smg/src/cli/validation/root.zig
const query = @import("query.zig");const unexpected = @import("unexpected.zig");const value = @import("value.zig");pub const choiceList = value.choiceList;pub const configuredLimitsOrReject = value.configuredLimitsOrReject;pub const noSuchOptionMessage = unexpected.noSuchOptionMessage;pub const optionWithForbiddenValue = value.optionWithForbiddenValue;pub const rejectForbiddenOptionValues = value.rejectForbiddenOptionValues;pub const rejectInvalidChoiceOption = value.rejectInvalidChoiceOption;pub const rejectInvalidFloatOption = value.rejectInvalidFloatOption;pub const rejectInvalidIntegerOption = value.rejectInvalidIntegerOption;pub const rejectInvalidIntegerRangeOption = value.rejectInvalidIntegerRangeOption;pub const rejectInvalidLine = value.rejectInvalidLine;pub const rejectInvalidMeta = value.rejectInvalidMeta;pub const rejectMissingOptionValues = value.rejectMissingOptionValues;pub const rejectMissingPaths = value.rejectMissingPaths;pub const rejectUnexpectedOptions = unexpected.rejectUnexpectedOptions;pub const rejectUnexpectedOptionsPlain = unexpected.rejectUnexpectedOptionsPlain;pub const rejectUnexpectedScanOptions = unexpected.rejectUnexpectedScanOptions;pub const unexpectedArgumentMessage = unexpected.unexpectedArgumentMessage;pub const validateQueryNameCommand = query.validateQueryNameCommand;Complete call list for cli.validation.validateQueryNameCommand
8 direct calls.
tiny.smg.cli.options.positional[function] attools/smg/src/cli/options.zig:35tiny.smg.cli.output.writeClickUsageError[function] attools/smg/src/cli/output.zig:85tiny.smg.cli.validation.rejectUnexpectedOptionsPlain[function] attools/smg/src/cli/validation/unexpected.zig:20tiny.smg.cli.validation.unexpectedArgumentMessage[function] attools/smg/src/cli/validation/unexpected.zig:101tiny.smg.cli.validation.rejectInvalidChoiceOption[function] attools/smg/src/cli/validation/value.zig:43tiny.smg.cli.validation.rejectInvalidIntegerOption[function] attools/smg/src/cli/validation/value.zig:59tiny.smg.cli.validation.rejectMissingOptionValues[function] attools/smg/src/cli/validation/value.zig:11tiny.smg.text.list.containsString[function] attools/smg/src/text/list.zig:3
Audit
| Definitions | 19 |
|---|---|
| Public names | 19 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |