summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gitano.lua14
-rw-r--r--lib/gitano/command.lua53
2 files changed, 67 insertions, 0 deletions
diff --git a/lib/gitano.lua b/lib/gitano.lua
index 766c2eb..c8f6bc4 100644
--- a/lib/gitano.lua
+++ b/lib/gitano.lua
@@ -42,7 +42,21 @@ local auth = require 'gitano.auth'
local plugins = require 'gitano.plugins'
local i18n = require 'gitano.i18n'
+local _VERSION = {1, 0, 0}
+_VERSION.major = _VERSION[1]
+_VERSION.minor = _VERSION[2]
+_VERSION.patch = _VERSION[3]
+
+local _VERSION_STRING = ("Gitano %d.%d.%d"):format(_VERSION.major,
+ _VERSION.minor,
+ _VERSION.patch)
+
+local _COPYRIGHT = "Copyright 2012-2017 Daniel Silverstone <dsilvers@digital-scurf.org>"
+
return {
+ VERSION = _VERSION,
+ VERSION_STRING = _VERSION_STRING,
+ COPYRIGHT = _COPYRIGHT,
util = util,
config = config,
repository = repository,
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]