diff --git a/norg/config/args.nim b/norg/config/args.nim index f1cd212..9c7fa5d 100644 --- a/norg/config/args.nim +++ b/norg/config/args.nim @@ -1,28 +1,19 @@ import argparse -import ../model/command_type +import ../model/config_type -type - NorgArgs* = object - config_file*: string - extract_destination*: string - command*: Command - repository*: string - archive*: string - stats*: bool - further_args*: seq[string] - -var norg_args*: NorgArgs = NorgArgs() +var norg_args*: NorgArgs = newNorgArgs() proc parseArgs*() = var p = newParser: help("Norg\r\nA portable borg backup wrapper utility") - option("-c", "--config", help="Config file to use.", required = true) + option("-c", "--config", help="Config file to use.") 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("-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)") 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.") + flag("-v","--version",help="Shows the current norg version") try: var opts = p.parse(commandLineParams()) norg_args.config_file = opts.config @@ -32,6 +23,9 @@ proc parseArgs*() = norg_args.archive = opts.archive norg_args.stats = opts.stats norg_args.further_args = opts.further_args + if opts.version: + echo "Norg Version: ", VERSION + quit(0) except ShortCircuit as err: if err.flag == "argparse_help": echo err.help diff --git a/norg/config/init.nim b/norg/config/init.nim index feac034..fc85936 100644 --- a/norg/config/init.nim +++ b/norg/config/init.nim @@ -3,12 +3,15 @@ import parsetoml import ../model/config_type import ../model/command_type import ../model/encryption_type +import ../model/args_type import notifier_config import actions_config import maintenance_config +export args_type export config_type + proc parseSourceDirectories*(in_conf: TomlValueRef): seq[string] = var src_dirs: seq[string] = @[] for dir in in_conf{"source_directories"}.getElems(): diff --git a/norg/model/args_type.nim b/norg/model/args_type.nim new file mode 100644 index 0000000..27c6e3f --- /dev/null +++ b/norg/model/args_type.nim @@ -0,0 +1,18 @@ +import command_type +export command_type + +type + NorgArgs* = object + config_file*: string + extract_destination*: string + command*: Command + repository*: string + archive*: string + stats*: bool + further_args*: seq[string] + + +proc newNorgArgs*(): NorgArgs = + var args = NorgArgs() + return args + diff --git a/norg/model/config_type.nim b/norg/model/config_type.nim index 49fbb17..93fcc49 100644 --- a/norg/model/config_type.nim +++ b/norg/model/config_type.nim @@ -3,14 +3,17 @@ import notifier_types import actions_type import maintenance_type import binary_type -import ../config/args +import args_type export repository_type export notifier_types export actions_type export maintenance_type export binary_type +export args_type +import ../utils/version +const VERSION*: string = getVersion() type NorgConfig* = ref object diff --git a/norg/norg.nim b/norg/norg.nim index d072f2f..119c063 100644 --- a/norg/norg.nim +++ b/norg/norg.nim @@ -8,7 +8,8 @@ import utils/actions proc start() = parseArgs() norg_config.args = norg_args - norg_config = parseConfigFile(norg_args.config_file) + if norg_args.config_file != "": + norg_config = parseConfigFile(norg_args.config_file) if norg_config.source_directories.len > 0 and norg_config.repositories.len > 0: run_actions(norg_config.actions.before_everything) for repo in norg_config.repositories: @@ -20,7 +21,7 @@ proc start() = restic.execute(norg_config, repo) run_actions(norg_config.actions.after_actions) run_actions(norg_config.actions.after_everything) - delEncryptionPassphraseInfo() + delEncryptionPassphraseInfo() when isMainModule: start() diff --git a/norg/utils/version.nim b/norg/utils/version.nim new file mode 100644 index 0000000..f164364 --- /dev/null +++ b/norg/utils/version.nim @@ -0,0 +1,10 @@ +import parsecfg +import streams + +proc getVersion*(): string = + let nimble = staticRead("../../norg.nimble") + var p: Config = loadConfig(newStringStream(nimble)) + let vers = p.getSectionValue("","version") + echo "Compiling version: v", vers + return "v" & vers +