diff --git a/norg/config/args.nim b/norg/config/args.nim index 9c7fa5d..86a6c16 100644 --- a/norg/config/args.nim +++ b/norg/config/args.nim @@ -5,15 +5,15 @@ var norg_args*: NorgArgs = newNorgArgs() proc parseArgs*() = 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("-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("-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)") + 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") + flag("-v","--version",help="Shows the current norg version.") try: var opts = p.parse(commandLineParams()) norg_args.config_file = opts.config @@ -23,9 +23,7 @@ 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) + norg_args.show_version = opts.version except ShortCircuit as err: if err.flag == "argparse_help": echo err.help diff --git a/norg/model/args_type.nim b/norg/model/args_type.nim index 27c6e3f..6160345 100644 --- a/norg/model/args_type.nim +++ b/norg/model/args_type.nim @@ -3,6 +3,7 @@ export command_type type NorgArgs* = object + show_version*: bool config_file*: string extract_destination*: string command*: Command diff --git a/norg/norg.nim b/norg/norg.nim index 119c063..f215189 100644 --- a/norg/norg.nim +++ b/norg/norg.nim @@ -5,23 +5,31 @@ import restic/restic import model/encryption_type import utils/actions +proc showVersion() = + echo "Norg Version: ", VERSION + quit(0) + proc start() = parseArgs() 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) - 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: - run_actions(norg_config.actions.before_actions) - case repo.tool - of BORG: - borg.execute(norg_config, repo) - of RESTIC: - restic.execute(norg_config, repo) - run_actions(norg_config.actions.after_actions) - run_actions(norg_config.actions.after_everything) - delEncryptionPassphraseInfo() + 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: + run_actions(norg_config.actions.before_actions) + case repo.tool + of BORG: + borg.execute(norg_config, repo) + of RESTIC: + restic.execute(norg_config, repo) + run_actions(norg_config.actions.after_actions) + run_actions(norg_config.actions.after_everything) + delEncryptionPassphraseInfo() + else: + echo "No Config File Provided" when isMainModule: start()