added version output

This commit is contained in:
Paul Wilde 2024-08-27 20:21:21 +01:00
parent c8933f9b09
commit 1f9c53b3f2
3 changed files with 28 additions and 21 deletions

View file

@ -5,15 +5,15 @@ var norg_args*: NorgArgs = newNorgArgs()
proc parseArgs*() = proc parseArgs*() =
var p = newParser: var p = newParser:
help("Norg\r\nA portable borg backup wrapper utility") help("Norg -- " & VERSION & "\r\nA portable borg backup wrapper utility.")
option("-c", "--config", help="Config file to use.") option("-c", "--config", help="Config file to use.")
option("-d", "--destination", help="Destination when extracting backup", required = false) option("-d", "--destination", help="Destination when extracting backup,", required = false)
option("-r", "--repository", help="Define an explicit repository to work on by either label or path.", required = false) option("-r", "--repository", help="Define an explicit repository to work on by either label or path.", required = false)
option("-a", "--archive", help="The archive or snapshot to operate on", required = false) option("-a", "--archive", help="The archive or snapshot to operate on.", required = false)
flag("-s","--stats",help="Provides statistics at the end of a backup (Borg only)") flag("-s","--stats",help="Provides statistics at the end of a backup (Borg only).")
arg("command", help="The command to run, defaults to 'create' which will perform a backup.", default=some("create")) arg("command", help="The command to run, defaults to 'create' which will perform a backup.", default=some("create"))
arg("further_args", nargs = -1, help="Any further arguments to send onto borg or restic.") arg("further_args", nargs = -1, help="Any further arguments to send onto borg or restic.")
flag("-v","--version",help="Shows the current norg version") flag("-v","--version",help="Shows the current norg version.")
try: try:
var opts = p.parse(commandLineParams()) var opts = p.parse(commandLineParams())
norg_args.config_file = opts.config norg_args.config_file = opts.config
@ -23,9 +23,7 @@ proc parseArgs*() =
norg_args.archive = opts.archive norg_args.archive = opts.archive
norg_args.stats = opts.stats norg_args.stats = opts.stats
norg_args.further_args = opts.further_args norg_args.further_args = opts.further_args
if opts.version: norg_args.show_version = opts.version
echo "Norg Version: ", VERSION
quit(0)
except ShortCircuit as err: except ShortCircuit as err:
if err.flag == "argparse_help": if err.flag == "argparse_help":
echo err.help echo err.help

View file

@ -3,6 +3,7 @@ export command_type
type type
NorgArgs* = object NorgArgs* = object
show_version*: bool
config_file*: string config_file*: string
extract_destination*: string extract_destination*: string
command*: Command command*: Command

View file

@ -5,10 +5,16 @@ import restic/restic
import model/encryption_type import model/encryption_type
import utils/actions import utils/actions
proc showVersion() =
echo "Norg Version: ", VERSION
quit(0)
proc start() = proc start() =
parseArgs() parseArgs()
norg_config.args = norg_args norg_config.args = norg_args
if norg_args.config_file != "": if norg_args.show_version:
showVersion()
elif norg_args.config_file != "":
norg_config = parseConfigFile(norg_args.config_file) norg_config = parseConfigFile(norg_args.config_file)
if norg_config.source_directories.len > 0 and norg_config.repositories.len > 0: if norg_config.source_directories.len > 0 and norg_config.repositories.len > 0:
run_actions(norg_config.actions.before_everything) run_actions(norg_config.actions.before_everything)
@ -22,6 +28,8 @@ proc start() =
run_actions(norg_config.actions.after_actions) run_actions(norg_config.actions.after_actions)
run_actions(norg_config.actions.after_everything) run_actions(norg_config.actions.after_everything)
delEncryptionPassphraseInfo() delEncryptionPassphraseInfo()
else:
echo "No Config File Provided"
when isMainModule: when isMainModule:
start() start()