@@ -64,15 +64,27 @@ const Args = struct {
6464 }
6565
6666 pub fn deinit (self : Self , allocator : std.mem.Allocator ) void {
67- if (self .api_key ) | s | allocator .free (s );
68- if (self .json_input_file ) | s | allocator .free (s );
69- if (self .json_output_file ) | s | allocator .free (s );
70- if (self .excluded_repos ) | s | allocator .free (s );
71- if (self .excluded_langs ) | s | allocator .free (s );
72- if (self .overview_output_file ) | s | allocator .free (s );
73- if (self .languages_output_file ) | s | allocator .free (s );
74- if (self .overview_template ) | s | allocator .free (s );
75- if (self .languages_template ) | s | allocator .free (s );
67+ inline for (@typeInfo (Self ).@"struct" .fields ) | field | {
68+ switch (@typeInfo (field .type )) {
69+ .optional = > | optional | {
70+ switch (@typeInfo (optional .child )) {
71+ .pointer = > | pointer | switch (pointer .size ) {
72+ .slice = > if (@field (self , field .name )) | p |
73+ allocator .free (p ),
74+ else = > comptime unreachable ,
75+ },
76+ .bool , .int = > {},
77+ else = > comptime unreachable ,
78+ }
79+ },
80+ .pointer = > | p | switch (p .size ) {
81+ .slice = > allocator .free (@field (self , field .name )),
82+ else = > comptime unreachable ,
83+ },
84+ .bool , .int = > {},
85+ else = > comptime unreachable ,
86+ }
87+ }
7688 }
7789};
7890
0 commit comments