summaryrefslogtreecommitdiff
path: root/lib/gitano
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2017-01-15 15:46:54 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2017-01-15 15:46:54 +0000
commit5d278aa81dcacf5b9cf54dae67103ced19d45606 (patch)
treea881a736871e5ad48c800e3b03cab1d76c493733 /lib/gitano
parentaf860441720400898a7daa482abe8129742f2301 (diff)
downloadgitano-5d278aa81dcacf5b9cf54dae67103ced19d45606.tar.gz
Add a version number system to Gitano
Diffstat (limited to 'lib/gitano')
-rw-r--r--lib/gitano/command.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua
index 50d4e89..f581dc1 100644
--- a/lib/gitano/command.lua
+++ b/lib/gitano/command.lua
@@ -107,6 +107,59 @@ local function get_cmd(cmdname)
}
end
+local builtin_version_short = "Get the Gitano version"
+local builtin_version_helptext = [[
+usage: version [machine]
+
+Without an argument, display the version and basic copyright information for
+Gitano in a form which a human can parse.
+
+With the 'machine' command, display the Gitano version as a machine-parseable
+list of values instead.
+
+**NOTE**: the format of the machine-parseable output is not guaranteed stable
+at this time.
+]]
+
+local function builtin_version_validate(config, _, cmdline)
+ if #cmdline > 2 then
+ log.error("usage: version [machine]")
+ return false
+ end
+ if #cmdline == 2 and cmdline[2] ~= "machine" then
+ log.error("usage: version [machine]")
+ return false
+ end
+ return true
+end
+
+local function builtin_version_prep(config, _, cmdline, context)
+ return "allow", "Always allowed to ask for the version"
+end
+
+local function builtin_version_run(config, _, cmdline, env)
+ -- We do this lazily because otherwise circular includes get in our way
+ local _gitano = require "gitano"
+ if #cmdline == 1 then
+ log.state(_gitano.VERSION_STRING)
+ log.state(_gitano.COPYRIGHT)
+ else
+ -- Machine-parseable version
+ log.state(("VERSION:%d.%d.%d"):format(
+ _gitano.VERSION.major,
+ _gitano.VERSION.minor,
+ _gitano.VERSION.patch))
+ log.state(("MAJOR:%d"):format(_gitano.VERSION.major))
+ log.state(("MINOR:%d"):format(_gitano.VERSION.minor))
+ log.state(("PATCH:%d"):format(_gitano.VERSION.patch))
+ end
+ return "exit", 0
+end
+
+assert(register_cmd("version", builtin_version_short, builtin_version_helptext,
+ builtin_version_validate, builtin_version_prep,
+ builtin_version_run, false, false))
+
local builtin_help_short = "Ask for help"
local builtin_help_helptext = [[
usage: help [admin|command]