mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 21:31:28 +02:00
MINOR: version: add -vq, -vqb, and -vqs flags for concise version output
This patch introduces three new command line flags to display HAProxy version info more flexibly: - `-vqs` outputs the short version string without commit info (e.g., "3.3.1"). - `-vqb` outputs only the branch (major.minor) part of the version (e.g., "3.3"). - `-vq` outputs the full version string with suffixes (e.g., "3.3.1-dev5-1bb975-71"). This allows easier parsing of version info in automation while keeping existing -v and -vv behaviors. The command line argument parsing now calls `display_version_plain()` with a display_mode parameter to select the desired output format. The function handles stripping of commit or patch info as needed, depending on the mode. Signed-off-by: Nikita Kurashkin <nkurashkin@stsoft.ru>
This commit is contained in:
parent
5d9abc68b4
commit
ef73fe2584
@ -616,6 +616,42 @@ void display_version()
|
||||
}
|
||||
}
|
||||
|
||||
/* display_mode:
|
||||
* 0 = short version (e.g., "3.3.1")
|
||||
* 1 = full version (e.g., "3.3.1-dev5-1bb975-71")
|
||||
* 2 = branch version (e.g., "3.3")
|
||||
*/
|
||||
void display_version_plain(int display_mode)
|
||||
{
|
||||
char out[30] = "";
|
||||
int dots = 0;
|
||||
int i;
|
||||
|
||||
if (display_mode == 1) {
|
||||
printf("%s\n", haproxy_version);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(out) - 1 && haproxy_version[i]; i++) {
|
||||
if (display_mode == 2) {
|
||||
if (haproxy_version[i] == '.') dots++;
|
||||
if (dots == 2 || haproxy_version[i] == '-') {
|
||||
out[i] = '\0';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if ((haproxy_version[i] < '0' || haproxy_version[i] > '9') && haproxy_version[i] != '.') {
|
||||
out[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
out[i] = haproxy_version[i];
|
||||
out[i+1] = '\0';
|
||||
}
|
||||
|
||||
printf("%s\n", out);
|
||||
}
|
||||
|
||||
static void display_build_opts()
|
||||
{
|
||||
const char **opt;
|
||||
@ -658,6 +694,7 @@ static void usage(char *name)
|
||||
"D ] [ -n <maxconn> ] [ -N <maxpconn> ]\n"
|
||||
" [ -p <pidfile> ] [ -m <max megs> ] [ -C <dir> ] [-- <cfgfile>*]\n"
|
||||
" -v displays version ; -vv shows known build options.\n"
|
||||
" -vq/-vqs/-vqb only displays version, short version, branch.\n"
|
||||
" -d enters debug mode ; -db only disables background mode.\n"
|
||||
" -dM[<byte>,help,...] debug memory (default: poison with <byte>/0x50)\n"
|
||||
" -dt activate traces on stderr\n"
|
||||
@ -1477,11 +1514,25 @@ static void init_args(int argc, char **argv)
|
||||
|
||||
/* 1 arg */
|
||||
if (*flag == 'v') {
|
||||
if (flag[1] == 'q' && flag[2] == 's' && flag[3] == '\0') {
|
||||
display_version_plain(0); // -vqs
|
||||
deinit_and_exit(0);
|
||||
}
|
||||
else if (flag[1] == 'q' && flag[2] == 'b' && flag[3] == '\0') {
|
||||
display_version_plain(2); // -vqb
|
||||
deinit_and_exit(0);
|
||||
}
|
||||
else if (flag[1] == 'q' && flag[2] == '\0') {
|
||||
display_version_plain(1); // -vq
|
||||
deinit_and_exit(0);
|
||||
}
|
||||
else {
|
||||
display_version();
|
||||
if (flag[1] == 'v') /* -vv */
|
||||
if (flag[1] == 'v') // -vv
|
||||
display_build_opts();
|
||||
deinit_and_exit(0);
|
||||
}
|
||||
}
|
||||
#if defined(USE_EPOLL)
|
||||
else if (*flag == 'd' && flag[1] == 'e')
|
||||
global.tune.options &= ~GTUNE_USE_EPOLL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user