From: Nikita Kurashkin <nkurash...@stsoft.ru> This patch introduces two new CLI flags to display HAProxy version info in a cleaner way:
- `-vq` outputs a short, minimal version string (e.g., "3.3"). - `-vql` outputs the full version string with suffixes (e.g., "3.3-dev5-1bb975-71"). This addresses the need for easy parsing of version info in automation without breaking existing -v and -vv behaviors (see #2509). In CLI argument parsing, handle `-vq` and `-vql` by calling `display_version_plain()` with a flag indicating short or full output, then exit. This function prints only the version number in a simplified format, omitting extra info shown by `display_version()`. Signed-off-by: Nikita Kurashkin <nkurash...@stsoft.ru> --- src/haproxy.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/haproxy.c b/src/haproxy.c index e0f196a34..5a7ec705a 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -614,6 +614,23 @@ void display_version() } } +void display_version_plain(int full_version) +{ + if (full_version) { + printf("%s\n", haproxy_version); + } else { + char base_version[20]; + char *del; + for (del = haproxy_version; *del; del++) { + if (*del == '.') continue; + if (*del < '0' || *del > '9') + break; + } + strlcpy2(base_version, haproxy_version, del - haproxy_version + 1); + printf("%s\n", base_version); + } +} + static void display_build_opts() { const char **opt; @@ -1472,10 +1489,20 @@ static void init_args(int argc, char **argv) /* 1 arg */ if (*flag == 'v') { - display_version(); - if (flag[1] == 'v') /* -vv */ - display_build_opts(); - deinit_and_exit(0); + if (flag[1] == 'q' && flag[2] == '\0') { /* -vq */ + display_version_plain(0); + deinit_and_exit(0); + } + else if (flag[1] == 'q' && flag[2] == 'l' && flag[3] == '\0') { /* -vql */ + display_version_plain(1); + deinit_and_exit(0); + } + else { + display_version(); + if (flag[1] == 'v') /* -vv */ + display_build_opts(); + deinit_and_exit(0); + } } #if defined(USE_EPOLL) else if (*flag == 'd' && flag[1] == 'e') -- 2.34.1