mirror of
https://github.com/MasterQ32/zig-args.git
synced 2024-05-05 15:11:09 +02:00
Update to latest master.
This commit is contained in:
parent
e062a59aa2
commit
8bc65a2846
62
.github/workflows/blank.yml
vendored
62
.github/workflows/blank.yml
vendored
|
@ -1,62 +0,0 @@
|
||||||
name: Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ master ]
|
|
||||||
schedule:
|
|
||||||
- cron: '0 5 * * *' # run at 5 AM UTC
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
linux:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Setup Zig
|
|
||||||
uses: goto-bus-stop/setup-zig@v1
|
|
||||||
with:
|
|
||||||
version: master
|
|
||||||
|
|
||||||
- name: Build demo
|
|
||||||
run: |
|
|
||||||
zig build-exe demo.zig
|
|
||||||
|
|
||||||
- name: Run demo
|
|
||||||
run: ./demo
|
|
||||||
|
|
||||||
windows:
|
|
||||||
runs-on: windows-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Setup Zig
|
|
||||||
uses: goto-bus-stop/setup-zig@v1
|
|
||||||
with:
|
|
||||||
version: master
|
|
||||||
|
|
||||||
- name: Build demo
|
|
||||||
run: zig build-exe demo.zig
|
|
||||||
|
|
||||||
- name: Run demo
|
|
||||||
run: ./demo.exe
|
|
||||||
|
|
||||||
macos:
|
|
||||||
runs-on: macos-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Setup Zig
|
|
||||||
uses: goto-bus-stop/setup-zig@v1
|
|
||||||
with:
|
|
||||||
version: master
|
|
||||||
|
|
||||||
- name: Build demo
|
|
||||||
run: zig build-exe demo.zig
|
|
||||||
|
|
||||||
- name: Run demo
|
|
||||||
run: ./demo
|
|
32
.github/workflows/cross-build.yml
vendored
Normal file
32
.github/workflows/cross-build.yml
vendored
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
pull_request:
|
||||||
|
branches: [master]
|
||||||
|
schedule:
|
||||||
|
- cron: "0 5 * * *" # run at 5 AM UTC
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
cross-build:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
platform: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
runs-on: ${{ matrix.platform }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Zig
|
||||||
|
uses: goto-bus-stop/setup-zig@v1
|
||||||
|
with:
|
||||||
|
version: master
|
||||||
|
|
||||||
|
- name: Build demo
|
||||||
|
run: |
|
||||||
|
zig build-exe demo.zig
|
||||||
|
|
||||||
|
- name: Run demo
|
||||||
|
run: ./demo --output demo --with-offset --signed_number=-10 --unsigned_number 20 --mode slow help this is borked
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
zig-cache
|
||||||
|
demo
|
||||||
|
demo.exe
|
7
args.zig
7
args.zig
|
@ -86,15 +86,16 @@ pub fn parse(comptime Spec: type, args: *std.process.ArgIterator, allocator: *st
|
||||||
if (fld.name.len != 1)
|
if (fld.name.len != 1)
|
||||||
@compileError("All shorthand fields must be exactly one character long!");
|
@compileError("All shorthand fields must be exactly one character long!");
|
||||||
if (fld.name[0] == char) {
|
if (fld.name[0] == char) {
|
||||||
const real_fld = std.meta.fieldInfo(Spec, @field(Spec.shorthands, fld.name));
|
const real_name = @field(Spec.shorthands, fld.name);
|
||||||
|
const real_fld_type = @TypeOf(@field(result.options, real_name));
|
||||||
|
|
||||||
// -2 because we stripped of the "-" at the beginning
|
// -2 because we stripped of the "-" at the beginning
|
||||||
if (requiresArg(real_fld.field_type) and index != item.len - 2) {
|
if (requiresArg(real_fld_type) and index != item.len - 2) {
|
||||||
try std.io.getStdErr().writer().writeAll("An option with argument must be the last option for short command line options.\n");
|
try std.io.getStdErr().writer().writeAll("An option with argument must be the last option for short command line options.\n");
|
||||||
return error.EncounteredUnexpectedArgument;
|
return error.EncounteredUnexpectedArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
try parseOption(Spec, &result, args, real_fld.name, null);
|
try parseOption(Spec, &result, args, real_name, null);
|
||||||
|
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
6
demo.zig
6
demo.zig
|
@ -25,11 +25,11 @@ pub fn main() !void {
|
||||||
}, argsAllocator);
|
}, argsAllocator);
|
||||||
defer options.deinit();
|
defer options.deinit();
|
||||||
|
|
||||||
std.debug.print("executable name: {}\n", .{options.executable_name});
|
std.debug.print("executable name: {s}\n", .{options.executable_name});
|
||||||
|
|
||||||
std.debug.print("parsed options:\n", .{});
|
std.debug.print("parsed options:\n", .{});
|
||||||
inline for (std.meta.fields(@TypeOf(options.options))) |fld| {
|
inline for (std.meta.fields(@TypeOf(options.options))) |fld| {
|
||||||
std.debug.print("\t{} = {}\n", .{
|
std.debug.print("\t{s} = {}\n", .{
|
||||||
fld.name,
|
fld.name,
|
||||||
@field(options.options, fld.name),
|
@field(options.options, fld.name),
|
||||||
});
|
});
|
||||||
|
@ -37,6 +37,6 @@ pub fn main() !void {
|
||||||
|
|
||||||
std.debug.print("parsed positionals:\n", .{});
|
std.debug.print("parsed positionals:\n", .{});
|
||||||
for (options.positionals) |arg| {
|
for (options.positionals) |arg| {
|
||||||
std.debug.print("\t'{}'\n", .{arg});
|
std.debug.print("\t'{s}'\n", .{arg});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue