Skip to content

Fetch and parse the version number of most CLI apps

License

Notifications You must be signed in to change notification settings

kaushalmodi/version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fetch and parse the version for almost all CLI apps

https://github.com/kaushalmodi/version/actions/workflows/test.yml/badge.svg https://github.com/kaushalmodi/version/actions/workflows/docs.yml/badge.svg

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 switchExamples
–versionnim, GNU projects like gcc, emacs, rg
-Vtmux, p4
-vtcc
versionGo projects like hugo

Install

nimble install https://github.com/kaushalmodi/version

API Documentation

https://kaushalmodi.github.io/version/

Library

Compile time

import version

static:
  doAssert "nim".getVersionCT() == (NimMajor, NimMinor, NimPatch)
  doAssert "gcc".getVersionCT() > (9, 0, 0)

Run time

import version

doAssert "nim".getVersion() == (NimMajor, NimMinor, NimPatch)
doAssert "hugo".getVersion() >= (0, 60, 0)

CLI Utility

Download

If you do not want to nimble install this package, you can download the latest static binary (musl) for Linux 64-bit from Releases.

Input from terminal

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

Input from a pipe

The arguments can also be piped into the version executable:

echo "nim emacs hugo tcc perl tmux" | version

Prior art by others

semver

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 time getVersionCT() 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.

Known limitations

Versions of multiple tools on the same line

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.

tcl

To find the Tcl version on your system, run:

echo 'puts [info patchlevel]; exit 0' | tclsh

reference