microsoft/wifi-ztp

Implement --version option

forwardpointer opened this issue · 3 comments

Is your feature request related to a problem? Please describe.
.

Describe the solution you'd like
I would like ztpd --version to output the version that the ztpd binary is. To my knowledge there is no other way to check the version of the binary. Having this information outputted in the logs would also help debugging.

Describe alternatives you've considered
.

Additional context
.

Please ensure the version is defined using semver format. It should also be easily checked in the code with pre-processor macros. Usually, having integral and string versions are useful. Eg. (something like below, not necessarily exactly this):

#define xstr(s) str(s)
#define str(s) #s

#define VERSION_BUILD(_major, _minor_, _build) ((_major << 24 | _minor << 16 | _build))
#define ZTP_LIB_VERSION_MAJOR 3
#define ZTP_LIB_VERSION_MINOR 11
#define ZTP_LIB_VERSION_PATCH 1

// Define numerical version for pre-process macro checks/comparisons
#define ZTP_LIB_VERSION_3_11_1 VERSION_BUILD(ZTP_LIB_VERSION_MAJOR, ZTP_LIB_VERSION_MINOR, ZTP_LIB_VERSION_PATCH)
#define ZTP_VERSION_CURRENT ZTP_LIB_VERSION_3_11_1

#define ZTP_VERSION_CURRENT_STR "v" xstr(ZTP_LIB_VERSION_MAJOR) "." xstr(ZTP_LIB_VERSION_MINOR) "." xtr(ZTP_LIB_VERSION_PATCH) 

#if ZTP_VERSION_CURRENT > ZTP_VERSION_3_11_1
// do version conditional-things
#endif

...
main(int argv, char *argv[]) {
   switch (optarg) {
   case 'v':
        printf("ztpd " ZTP_VERSION_CURRENT_STR);
        break;
   // ...
   }
}

A current workaround for this is to query the package manager:

rpm -qa | grep ztpd

A current workaround for this is to query the package manager:

rpm -qa | grep ztpd

This works ok for rpm-based distros, but won't work for .deb-based distros (Debian, Ubuntu). For the former, consider using rpm query tags to extract very specific versioning information. Also, instead of grepping the output, you should instead specify the package name explicitly, rpm -qa ztpd. Be careful as well, since if multiple versions are installed, you need to take care to format/filter/select the expected output. It's not trivial to list the "latest"/"newest" version installed.