Skip to content

Commit 72fa419

Browse files
eeppjgalar
authored andcommitted
cli: print full version name
Include the release's name and name description, the Git revision description, and extra information. Signed-off-by: Philippe Proulx <[email protected]> Change-Id: I478da57eb24b6a8d0f9c7a0b7b1fb8a41d8e4867 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2839 Reviewed-by: Francis Deslauriers <[email protected]> Tested-by: jenkins <[email protected]>
1 parent a0446fa commit 72fa419

File tree

1 file changed

+67
-4
lines changed

1 file changed

+67
-4
lines changed

src/cli/babeltrace2-cfg-cli-args.c

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,79 @@ void plugin_comp_cls_names(const char *arg, char **name, char **plugin,
191191
return;
192192
}
193193

194+
static
195+
void print_and_indent(const char *str)
196+
{
197+
const char *ch = &str[0];
198+
199+
for (; *ch != '\0'; ch++) {
200+
if (*ch == '\n') {
201+
if (ch[1] != '\0') {
202+
printf("\n ");
203+
}
204+
} else {
205+
printf("%c", *ch);
206+
}
207+
}
208+
209+
printf("\n");
210+
}
211+
194212
/*
195213
* Prints the Babeltrace version.
196214
*/
197215
static
198216
void print_version(void)
199217
{
200-
if (BT_VERSION_GIT[0] == '\0') {
201-
puts("Babeltrace " VERSION);
202-
} else {
203-
puts("Babeltrace " VERSION " - " BT_VERSION_GIT);
218+
bool has_extra_name = strlen(BT_VERSION_EXTRA_NAME) > 0;
219+
bool has_extra_description = strlen(BT_VERSION_EXTRA_DESCRIPTION) > 0;
220+
bool has_extra_patch_names = strlen(BT_VERSION_EXTRA_PATCHES) > 0;
221+
bool has_extra = has_extra_name || has_extra_description ||
222+
has_extra_patch_names;
223+
224+
printf("Babeltrace " VERSION);
225+
226+
if (strlen(BT_VERSION_NAME) > 0) {
227+
printf(" \"%s\"", BT_VERSION_NAME);
228+
}
229+
230+
if (strlen(BT_VERSION_GIT) > 0) {
231+
printf(" [%s]", BT_VERSION_GIT);
232+
}
233+
234+
printf("\n");
235+
236+
if (strlen(BT_VERSION_DESCRIPTION) > 0) {
237+
unsigned int columns;
238+
GString *descr;
239+
240+
if (bt_common_get_term_size(&columns, NULL) < 0) {
241+
/* Width not found: default to 80 */
242+
columns = 80;
243+
}
244+
245+
descr = bt_common_fold(BT_VERSION_DESCRIPTION, columns, 0);
246+
BT_ASSERT(descr);
247+
printf("\n%s\n", descr->str);
248+
g_string_free(descr, TRUE);
249+
}
250+
251+
if (has_extra) {
252+
printf("\n");
253+
254+
if (has_extra_name) {
255+
printf("Extra name: %s\n", BT_VERSION_EXTRA_NAME);
256+
}
257+
258+
if (has_extra_description) {
259+
printf("Extra description:\n ");
260+
print_and_indent(BT_VERSION_EXTRA_DESCRIPTION);
261+
}
262+
263+
if (has_extra_patch_names) {
264+
printf("Extra patch names:\n ");
265+
print_and_indent(BT_VERSION_EXTRA_PATCHES);
266+
}
204267
}
205268
}
206269

0 commit comments

Comments
 (0)