version provides a Nim library as well as a standalone CLI utility to fetch and parse the version info for almost any CLI app.
This project works for apps that use one of these switches to return the version info:
App switch | Examples |
---|---|
–version | nim, GNU projects like gcc, emacs, rg |
-V | tmux, p4 |
-v | tcc |
version | Go projects like hugo |
nimble install https://github.com/kaushalmodi/version
https://kaushalmodi.github.io/version/
import version
static:
doAssert "nim".getVersionCT() == (NimMajor, NimMinor, NimPatch)
doAssert "gcc".getVersionCT() > (9, 0, 0)
import version
doAssert "nim".getVersion() == (NimMajor, NimMinor, NimPatch)
doAssert "hugo".getVersion() >= (0, 60, 0)
If you do not want to nimble install
this package, you can download
the latest static binary (musl) for Linux 64-bit from Releases.
version nim emacs hugo tcc perl tmux
Above outputs:
nim version: 1.3.5 Nim Compiler Version 1.3.5 [Linux: amd64] Compiled at 2020-05-19 Copyright (c) 2006-2020 by Andreas Rumpf git hash: e909486e5cde5a4a77cd6f21b42fc9ab38ec2ae6 active boot switches: -d:release emacs version: 27.0.91 GNU Emacs 27.0.91 Copyright (C) 2020 Free Software Foundation, Inc. GNU Emacs comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of GNU Emacs under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING. hugo version: 0.71.0 Hugo Static Site Generator v0.71.0-06150C87 linux/amd64 BuildDate: 2020-05-18T16:08:02Z tcc version: 0.9.27 tcc version 0.9.27 (x86_64 Linux) perl version: 5.22.0 This is perl 5, version 22, subversion 0 (v5.22.0) built for x86_64-linux Copyright 1987-2015, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. tmux version: 3.1.99 tmux next-3.2
The arguments can also be piped into the version
executable:
echo "nim emacs hugo tcc perl tmux" | version
semver is a semantic versioning parser for Nim.
version is a bit different than semver because:
- This is designed (or attempted to) to return a version tuple for any CLI app.
- The run time
getVersion()
and compile timegetVersionCT()
procs return a generic 3-field tuple that can be right-away used with Nim’s inbuilt comparison operators. - This library also runs as a standalone binary which attempts to
return the version info for any application (issues/PR’s are of
course welcome if you have an app that doesn’t work with
this). Example:
version nim emacs hugo gcc tcc tmux perl python
.
Some tools like PyPy (ref) output versions of other tools as well on
the same line. While this issue doesn’t happen specifically when
running version pypy
, version
will return the version of the wrong
tool if that tool’s version shows up first on the line. Here’s a dummy
example:
> version mytool mytool version: 1.1.1 othertool 1.1.1 mytool 2.2.2
But the good thing is that the full version string is also printed.
To find the Tcl version on your system, run:
echo 'puts [info patchlevel]; exit 0' | tclsh