Skip to content

Commit ff79a14

Browse files
authored
-h: Refactor out colored help printing code (#5421)
1 parent 3a41342 commit ff79a14

File tree

13 files changed

+36
-98
lines changed

13 files changed

+36
-98
lines changed

binrz/rz-test/rz-test.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ static int help(bool verbose) {
8888
"-x", "[num]", "Number of expected failed tests",
8989
// clang-format on
9090
};
91-
size_t maxFlagAndArgLength = rz_print_options_get_max_len(options, RZ_ARRAY_SIZE(options), NULL);
92-
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
93-
if (i + 1 < RZ_ARRAY_SIZE(options)) {
94-
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
95-
}
96-
}
91+
rz_print_colored_help(options, RZ_ARRAY_SIZE(options), false);
9792
printf("Supported test types: @json @unit @fuzz @cmds\n"
9893
"OS/Arch for archos tests: " RZ_TEST_ARCH_OS "\n");
9994
}

librz/include/rz_util/rz_print.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,7 @@ RZ_API RZ_OWN char *rz_print_json_indent(RZ_NULLABLE const char *s, bool color,
234234
RZ_API char *rz_print_json_human(const char *s);
235235

236236
RZ_API RZ_OWN RzStrBuf *rz_print_colorize_asm_str(RZ_BORROW RzPrint *p, const RzAsmTokenString *toks);
237-
RZ_API size_t rz_print_options_get_max_len(const char **options, size_t options_len,
238-
RZ_NULLABLE size_t *maxDescLength);
239-
RZ_API void rz_print_colored_help_option(const char *flag, const char *arg, const char *desc,
240-
size_t maxFlagAndArgLength);
241-
RZ_API void rz_print_colored_help_option_example(RZ_NULLABLE const char *flag, RZ_NULLABLE const char *arg,
242-
const char *desc, size_t maxFlagAndArgLength, RZ_NULLABLE const char *example, size_t maxDescLength);
237+
RZ_API void rz_print_colored_help(const char **options, size_t options_len, bool have_examples);
243238
#endif
244239

245240
#ifdef __cplusplus

librz/main/rizin.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,7 @@ static int main_help(RZ_BORROW RZ_NONNULL RzCore *core, int line) {
139139
"-z, -zz", "", "Do not load strings or load them even in raw",
140140
// clang-format on
141141
};
142-
size_t maxFlagAndArgLength = rz_print_options_get_max_len(options, RZ_ARRAY_SIZE(options), NULL);
143-
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
144-
if (i + 1 < RZ_ARRAY_SIZE(options)) {
145-
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
146-
}
147-
}
142+
rz_print_colored_help(options, RZ_ARRAY_SIZE(options), false);
148143
}
149144
if (line == 2) {
150145
char *datahome = rz_path_home_prefix(RZ_DATADIR);

librz/main/rz-asm.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,7 @@ static int rasm_show_help(int v) {
207207
// clang-format on
208208
};
209209
if (v != 1) {
210-
size_t maxFlagAndArgLength = rz_print_options_get_max_len(options, RZ_ARRAY_SIZE(options), NULL);
211-
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
212-
if (i + 1 < RZ_ARRAY_SIZE(options)) {
213-
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
214-
}
215-
}
210+
rz_print_colored_help(options, RZ_ARRAY_SIZE(options), false);
216211
}
217212
printf(" If '-l' value is greater than output length, output is padded with nops\n"
218213
" If the last argument is '-' reads from stdin\n"

librz/main/rz-ax.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,7 @@ static int help(void) {
248248
#undef CF
249249
#undef CA
250250
#undef CR
251-
size_t maxDescLength = SIZE_MAX;
252-
size_t maxFlagAndArgLength = rz_print_options_get_max_len(options, RZ_ARRAY_SIZE(options), &maxDescLength);
253-
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 4) {
254-
if (i + 1 < RZ_ARRAY_SIZE(options)) {
255-
rz_print_colored_help_option_example(options[i], options[i + 1], options[i + 2],
256-
maxFlagAndArgLength, options[i + 3], maxDescLength);
257-
}
258-
}
251+
rz_print_colored_help(options, RZ_ARRAY_SIZE(options), true);
259252
return true;
260253
}
261254

librz/main/rz-bin.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,7 @@ static int rzbin_show_help(int v) {
218218
"-Z", "", "Guess size of binary program",
219219
// clang-format on
220220
};
221-
size_t maxFlagAndArgLength = rz_print_options_get_max_len(options, RZ_ARRAY_SIZE(options), NULL);
222-
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
223-
if (i + 1 < RZ_ARRAY_SIZE(options)) {
224-
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
225-
}
226-
}
221+
rz_print_colored_help(options, RZ_ARRAY_SIZE(options), false);
227222
}
228223
if (v) {
229224
printf("Environment:\n"

librz/main/rz-diff.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,7 @@ static void rz_diff_show_help(bool usage_only) {
243243
"", "", " symbols | compare symbols found in the files",
244244
// clang-format on
245245
};
246-
size_t maxFlagAndArgLength = rz_print_options_get_max_len(options, RZ_ARRAY_SIZE(options), NULL);
247-
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
248-
if (i + 1 < RZ_ARRAY_SIZE(options)) {
249-
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
250-
}
251-
}
252-
246+
rz_print_colored_help(options, RZ_ARRAY_SIZE(options), false);
253247
printf(
254248
"palette colors can be changed by adding the following lines\n"
255249
"inside the $HOME/.rizinrc file\n"

librz/main/rz-find.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,7 @@ static int show_help(const char *argv0, int line) {
223223
"-Z", "", "Show string found on each search hit",
224224
// clang-format on
225225
};
226-
size_t maxFlagAndArgLength = rz_print_options_get_max_len(options, RZ_ARRAY_SIZE(options), NULL);
227-
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
228-
if (i + 1 < RZ_ARRAY_SIZE(options)) {
229-
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
230-
}
231-
}
226+
rz_print_colored_help(options, RZ_ARRAY_SIZE(options), false);
232227
return 0;
233228
}
234229

librz/main/rz-gg.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ static int usage(int v) {
5050
"-z", "" ,"Output in C string syntax",
5151
// clang-format on
5252
};
53-
size_t maxFlagAndArgLength = rz_print_options_get_max_len(options, RZ_ARRAY_SIZE(options), NULL);
54-
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
55-
if (i + 1 < RZ_ARRAY_SIZE(options)) {
56-
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
57-
}
58-
}
53+
rz_print_colored_help(options, RZ_ARRAY_SIZE(options), false);
5954
}
6055
return 1;
6156
}

librz/main/rz-hash.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,7 @@ static void rz_hash_show_help(bool usage_only) {
109109
"", "", "If 's:' prefix is specified",
110110
// clang-format on
111111
};
112-
size_t maxFlagAndArgLength = rz_print_options_get_max_len(options, RZ_ARRAY_SIZE(options), NULL);
113-
for (int i = 0; i < RZ_ARRAY_SIZE(options); i += 3) {
114-
if (i + 1 < RZ_ARRAY_SIZE(options)) {
115-
rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxFlagAndArgLength);
116-
}
117-
}
112+
rz_print_colored_help(options, RZ_ARRAY_SIZE(options), false);
118113
}
119114

120115
static void rz_hash_show_algorithms(RzHashContext *ctx) {

0 commit comments

Comments
 (0)