@@ -64,15 +64,28 @@ 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 = > | p | switch (p .size ) {
72+ .slice = > allocator .free (
73+ @field (self , field .name ).? ,
74+ ),
75+ else = > comptime unreachable ,
76+ },
77+ .bool , .int = > {},
78+ else = > comptime unreachable ,
79+ }
80+ },
81+ .pointer = > | p | switch (p .size ) {
82+ .slice = > allocator .free (@field (self , field .name )),
83+ else = > comptime unreachable ,
84+ },
85+ .bool , .int = > {},
86+ else = > comptime unreachable ,
87+ }
88+ }
7689 }
7790};
7891
0 commit comments