Draft
Conversation
Updating with new lint results
tact1m4n3
reviewed
Jan 21, 2026
Comment on lines
+13
to
+128
| const Args = struct { | ||
| help: bool = false, | ||
| input_elf: ?[]const u8 = null, | ||
| output: ?[]const u8 = null, | ||
| chip_id: ?esp_image.ChipId = null, | ||
| min_rev_full: u16 = 0x0000, | ||
| max_rev_full: u16 = 0xffff, | ||
| dont_append_digest: bool = false, | ||
| flash_freq: esp_image.FlashFreq = .@"40m", | ||
| flash_mode: esp_image.FlashMode = .dio, | ||
| flash_size: esp_image.FlashSize = .@"4mb", | ||
| flash_mmu_page_size: esp_image.FlashMMU_PageSize = .default, | ||
| use_segments: bool = false, | ||
|
|
||
| pub fn parse(args: []const [:0]const u8) !Args { | ||
| var ret: Args = .{}; | ||
|
|
||
| var index: usize = 1; | ||
| while (index < args.len) : (index += 1) { | ||
| if (std.mem.eql(u8, args[index], "--help")) { | ||
| ret.help = true; | ||
| } else if (std.mem.eql(u8, args[index], "--output")) { | ||
| index += 1; | ||
| if (index >= args.len) { | ||
| return error.FormatRequiresArgument; | ||
| } | ||
| ret.output = args[index]; | ||
| } else if (std.mem.eql(u8, args[index], "--chip-id")) { | ||
| index += 1; | ||
| if (index >= args.len) { | ||
| return error.FormatRequiresArgument; | ||
| } | ||
| ret.chip_id = std.meta.stringToEnum(esp_image.ChipId, args[index]) orelse { | ||
| return error.InvalidChipId; | ||
| }; | ||
| } else if (std.mem.eql(u8, args[index], "--min-rev-full")) { | ||
| index += 1; | ||
| if (index >= args.len) { | ||
| return error.FormatRequiresArgument; | ||
| } | ||
| ret.min_rev_full = std.fmt.parseInt(u16, args[index], 10) catch { | ||
| return error.InvalidNumber; | ||
| }; | ||
| } else if (std.mem.eql(u8, args[index], "--max-rev-full")) { | ||
| index += 1; | ||
| if (index >= args.len) { | ||
| return error.FormatRequiresArgument; | ||
| } | ||
| ret.max_rev_full = std.fmt.parseInt(u16, args[index], 10) catch { | ||
| return error.InvalidNumber; | ||
| }; | ||
| } else if (std.mem.eql(u8, args[index], "--dont-append-digest")) { | ||
| ret.dont_append_digest = true; | ||
| } else if (std.mem.eql(u8, args[index], "--flash-freq")) { | ||
| index += 1; | ||
| if (index >= args.len) { | ||
| return error.FormatRequiresArgument; | ||
| } | ||
| ret.flash_freq = std.meta.stringToEnum(esp_image.FlashFreq, args[index]) orelse { | ||
| return error.InvalidFlashFreq; | ||
| }; | ||
| } else if (std.mem.eql(u8, args[index], "--flash-mode")) { | ||
| index += 1; | ||
| if (index >= args.len) { | ||
| return error.FormatRequiresArgument; | ||
| } | ||
| ret.flash_mode = std.meta.stringToEnum(esp_image.FlashMode, args[index]) orelse { | ||
| return error.InvalidFlashMode; | ||
| }; | ||
| } else if (std.mem.eql(u8, args[index], "--flash-size")) { | ||
| index += 1; | ||
| if (index >= args.len) { | ||
| return error.FormatRequiresArgument; | ||
| } | ||
| ret.flash_size = std.meta.stringToEnum(esp_image.FlashSize, args[index]) orelse { | ||
| return error.InvalidFlashSize; | ||
| }; | ||
| } else if (std.mem.eql(u8, args[index], "--flash-mmu-page-size")) { | ||
| index += 1; | ||
| if (index >= args.len) { | ||
| return error.FormatRequiresArgument; | ||
| } | ||
| ret.flash_mmu_page_size = std.meta.stringToEnum(esp_image.FlashMMU_PageSize, args[index]) orelse { | ||
| return error.InvalidFlashMMU_PageSize; | ||
| }; | ||
| } else if (std.mem.eql(u8, args[index], "--use-segments")) { | ||
| ret.use_segments = true; | ||
| } else { | ||
| if (ret.input_elf != null) { | ||
| std.log.err("extra arg: {s}", .{args[index]}); | ||
| return error.ExtraArguments; | ||
| } | ||
| ret.input_elf = args[index]; | ||
| } | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| const help_message = | ||
| \\--help Show this message | ||
| \\--output <str> Path to save the generated file | ||
| \\--chip-id <ChipId> Chip id | ||
| \\--min-rev-full <u16> Minimal chip revision (in format: major * 100 + minor) | ||
| \\--max-rev-full <u16> Maximal chip revision (in format: major * 100 + minor) | ||
| \\--dont-append-digest Don't append a SHA256 digest of the entire image after the checksum | ||
| \\--flash-freq <FlashFreq> SPI Flash frequency | ||
| \\--flash-mode <FlashMode> SPI Flash mode | ||
| \\--flash-size <FlashSize> SPI Flash size in megabytes | ||
| \\--flash-mmu-page-size <FlashMMU_PageSize> Flash MMU page size | ||
| \\--use-segments Use program headers instead of section headers | ||
| \\<str> | ||
| \\ | ||
| ; |
Collaborator
There was a problem hiding this comment.
Rewrote arg parsing to not depend on clap that isn't up to date with master. We should use the std cli parser when it lands
tact1m4n3
reviewed
Jan 21, 2026
| const AnyFuture = std.Io.AnyFuture; | ||
| const net = Io.net; | ||
|
|
||
| // Taken from https://codeberg.org/ziglang/zig/pulls/30691/ until it lands. |
Collaborator
There was a problem hiding this comment.
We should switch to Io.failing when it lands
Updating with new lint results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.