Skip to content

Add --struct option to layout - #2

Merged
Gulliby merged 1 commit into
mainfrom
feature/structpad-layout-struct-filter
Oct 14, 2026
Merged

Gulliby merged 1 commit into
mainfrom
feature/structpad-layout-struct-filter

Conversation

@Gulliby

@Gulliby Gulliby commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Requested by gulliby

Add a --struct NAME option to structpad layout.

Before: layout always printed every struct in the file, which is long when only one record matters, and a nested struct such as Frame cannot be cut out of the file because it needs Packet and Wire defined before it.

After: structpad layout --struct Frame --struct Wire net.sp prints only those structs, once each and in file order, with the same numbers as the full listing (nested structs are still resolved from the whole file). --struct=NAME also works, the option may appear anywhere and be repeated, and without it nothing changes.

struct Wire: size 5, align 1, padding 0, packed
offset   size  field
     0      1  kind: u8
     1      4  value: u32

struct Frame: size 56, align 8, padding 12
offset   size  field
     0      1  version: u8
     1      7  (padding)
     8     32  head: struct Packet
    40     10  tail: struct Wire[2]
    50      1  ok: bool
    51      5  (padding)

Errors exit with status 2 and one stderr line: invalid --struct "X", --struct needs a value, suggest does not take --struct, check does not take --struct, unknown struct "X" in --struct.

How: src/structpad/cli.py (option parsing, validation, usage line) and src/structpad/render.py (render_layout takes an optional selection), README section, the usage constant in tests/test_cli.py, and 13 new tests in tests/test_struct_select.py (131 in total). No dependency or CI changes.

Print the layout of only the named structs, once each and in file order, with the same numbers as the full listing. Documented in the README and covered by new tests.
@Gulliby
Gulliby merged commit fa54823 into main Oct 14, 2026
12 checks passed
@Gulliby
Gulliby deleted the feature/structpad-layout-struct-filter branch October 14, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant