https://github.com/kaushalmodi/version
Fetch and parse the version number of most CLI apps
https://github.com/kaushalmodi/version
api cli nim version
Last synced: 12 months ago
JSON representation
Fetch and parse the version number of most CLI apps
- Host: GitHub
- URL: https://github.com/kaushalmodi/version
- Owner: kaushalmodi
- License: mit
- Created: 2020-05-20T21:59:06.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-01T16:16:53.000Z (about 5 years ago)
- Last Synced: 2025-07-14T10:44:20.006Z (12 months ago)
- Topics: api, cli, nim, version
- Language: Nim
- Homepage: https://kaushalmodi.github.io/version/
- Size: 91.8 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
#+title: Fetch and parse the version for almost all CLI apps
#+author: Kaushal Modi
[[https://github.com/kaushalmodi/version/actions/workflows/test.yml][https://github.com/kaushalmodi/version/actions/workflows/test.yml/badge.svg]]
[[https://github.com/kaushalmodi/version/actions/workflows/docs.yml][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 switch | Examples |
|-------------+---------------------------------------|
| *--version* | nim, GNU projects like gcc, emacs, rg |
| *-V* | tmux, p4 |
| *-v* | tcc |
| *version* | Go projects like hugo |
|-------------+---------------------------------------|
* Install
#+begin_example
nimble install https://github.com/kaushalmodi/version
#+end_example
* API Documentation
[[https://kaushalmodi.github.io/version/][https://kaushalmodi.github.io/version/]]
* Library
** Compile time
#+begin_src nim
import version
static:
doAssert "nim".getVersionCT() == (NimMajor, NimMinor, NimPatch)
doAssert "gcc".getVersionCT() > (9, 0, 0)
#+end_src
** Run time
#+begin_src nim
import version
doAssert "nim".getVersion() == (NimMajor, NimMinor, NimPatch)
doAssert "hugo".getVersion() >= (0, 60, 0)
#+end_src
* 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 [[https://github.com/kaushalmodi/version/releases][Releases]].
** Input from terminal
#+begin_example
version nim emacs hugo tcc perl tmux
#+end_example
Above outputs:
#+begin_example
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
#+end_example
** Input from a pipe
The arguments can also be piped into the ~version~ executable:
#+begin_example
echo "nim emacs hugo tcc perl tmux" | version
#+end_example
* Prior art by others
** semver
[[https://github.com/euantorano/semver.nim][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 ([[https://github.com/kaushalmodi/version/issues/10#issue-622673454][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:
#+begin_example
> version mytool
mytool version: 1.1.1
othertool 1.1.1 mytool 2.2.2
#+end_example
/But the good thing is that the full version string is also printed./
** tcl
To find the Tcl version on your system, run:
#+begin_src shell
echo 'puts [info patchlevel]; exit 0' | tclsh
#+end_src
[[https://stackoverflow.com/a/19189401/1219634][reference]]