mirror of
https://github.com/MasterQ32/zig-args.git
synced 2024-09-16 20:24:03 +02:00
Changed to fix local variable is never mutated
This commit is contained in:
parent
7989929d05
commit
3797c1473b
3 changed files with 5 additions and 5 deletions
6
args.zig
6
args.zig
|
@ -401,7 +401,7 @@ fn parseInt(comptime T: type, str: []const u8) !T {
|
||||||
base1024 = true;
|
base1024 = true;
|
||||||
}
|
}
|
||||||
if (buf.len != 0) {
|
if (buf.len != 0) {
|
||||||
var pow: u3 = switch (buf[buf.len - 1]) {
|
const pow: u3 = switch (buf[buf.len - 1]) {
|
||||||
'k', 'K' => 1, //kilo
|
'k', 'K' => 1, //kilo
|
||||||
'm', 'M' => 2, //mega
|
'm', 'M' => 2, //mega
|
||||||
'g', 'G' => 3, //giga
|
'g', 'G' => 3, //giga
|
||||||
|
@ -415,7 +415,7 @@ fn parseInt(comptime T: type, str: []const u8) !T {
|
||||||
|
|
||||||
if (comptime std.math.maxInt(T) < 1024)
|
if (comptime std.math.maxInt(T) < 1024)
|
||||||
return error.Overflow;
|
return error.Overflow;
|
||||||
var base: T = if (base1024) 1024 else 1000;
|
const base: T = if (base1024) 1024 else 1000;
|
||||||
multiplier = try std.math.powi(T, base, @as(T, @intCast(pow)));
|
multiplier = try std.math.powi(T, base, @as(T, @intCast(pow)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -567,7 +567,7 @@ pub const ErrorCollection = struct {
|
||||||
|
|
||||||
/// Appends an error to the collection
|
/// Appends an error to the collection
|
||||||
fn insert(self: *Self, err: Error) !void {
|
fn insert(self: *Self, err: Error) !void {
|
||||||
var dupe = Error{
|
const dupe = Error{
|
||||||
.option = try self.arena.allocator().dupe(u8, err.option),
|
.option = try self.arena.allocator().dupe(u8, err.option),
|
||||||
.kind = switch (err.kind) {
|
.kind = switch (err.kind) {
|
||||||
.invalid_value => |v| Error.Kind{
|
.invalid_value => |v| Error.Kind{
|
||||||
|
|
2
demo.zig
2
demo.zig
|
@ -2,7 +2,7 @@ const std = @import("std");
|
||||||
const argsParser = @import("args");
|
const argsParser = @import("args");
|
||||||
|
|
||||||
pub fn main() !u8 {
|
pub fn main() !u8 {
|
||||||
var argsAllocator = std.heap.page_allocator;
|
const argsAllocator = std.heap.page_allocator;
|
||||||
|
|
||||||
const Options = struct {
|
const Options = struct {
|
||||||
// This declares long options for double hyphen
|
// This declares long options for double hyphen
|
||||||
|
|
|
@ -2,7 +2,7 @@ const std = @import("std");
|
||||||
const argsParser = @import("args");
|
const argsParser = @import("args");
|
||||||
|
|
||||||
pub fn main() !u8 {
|
pub fn main() !u8 {
|
||||||
var argsAllocator = std.heap.page_allocator;
|
const argsAllocator = std.heap.page_allocator;
|
||||||
|
|
||||||
const options = argsParser.parseWithVerbForCurrentProcess(
|
const options = argsParser.parseWithVerbForCurrentProcess(
|
||||||
struct {
|
struct {
|
||||||
|
|
Loading…
Reference in a new issue