@@ -71,3 +71,38 @@ project conventions that differ from typical C projects.
7171If you'd like, I can (a) shorten or expand any section, (b) add a short
7272walkthrough for adding a CLI flag in ` wg.c ` , or (c) include a sample PR
7373checklist. Which would you prefer?
74+
75+ ## Walkthrough — Add a small CLI flag to an existing subcommand
76+
77+ Example: add a simple ` --example-flag ` to the ` show ` subcommand.
78+
79+ - Files to edit: ` src/show.c ` (subcommand implementation) and, if needed,
80+ tests or ` man/ ` pages.
81+ - Typical steps:
82+ 1 . Locate the subcommand entry in ` src/wg.c ` (the ` subcommands[] ` table lists
83+ available subcommands and their ` *_main ` functions; ` show ` maps to ` show_main ` ).
84+ 2 . Open ` src/show.c ` and find ` show_main ` — it handles argc/argv for ` show ` .
85+ 3 . Add minimal flag parsing near the top of ` show_main ` . This project uses
86+ simple ` argv ` checks rather than a heavy option parser; follow existing
87+ patterns (see checks for ` argc ` and ` argv[1] ` already in ` show_main ` ).
88+ 4 . Implement the behavior (set a local ` bool ` or configuration struct and
89+ branch later in the printing functions such as ` pretty_print ` or
90+ ` ugly_print ` ).
91+ 5 . Build and run the subcommand locally: ` cd src && make V=1 && ./wg show --help ` .
92+ 6 . Run ` make check ` if you changed parsing or memory handling.
93+
94+ - Minimal illustrative code sketch (adapt to project's helpers):
95+
96+ ``` c
97+ // in src/show.c, inside show_main before printing
98+ bool example_flag = false ;
99+ for (int i = 1 ; i < argc; ++i) {
100+ if (!strcmp(argv[ i] , "--example-flag")) {
101+ example_flag = true;
102+ // optionally remove the consumed arg or shift argv
103+ }
104+ }
105+ // Later, in pretty_print or dump_print, use `example_flag` to alter output
106+ ```
107+
108+ Keep changes small and follow existing formatting and error handling patterns.
0 commit comments