2024-08-16 17:40:24 +02:00
|
|
|
import argparse
|
2024-08-27 20:58:50 +02:00
|
|
|
import ../model/config_type
|
2024-08-16 17:40:24 +02:00
|
|
|
|
2024-08-27 20:58:50 +02:00
|
|
|
var norg_args*: NorgArgs = newNorgArgs()
|
2024-08-16 17:40:24 +02:00
|
|
|
|
|
|
|
proc parseArgs*() =
|
|
|
|
var p = newParser:
|
2024-11-25 12:15:15 +01:00
|
|
|
help("Norg -- " & VERSION & "\r\nA portable borg backup and restic orchestration tool.")
|
2024-08-27 20:58:50 +02:00
|
|
|
option("-c", "--config", help="Config file to use.")
|
2024-08-27 21:21:21 +02:00
|
|
|
option("-d", "--destination", help="Destination when extracting backup,", required = false)
|
2024-08-23 13:04:27 +02:00
|
|
|
option("-r", "--repository", help="Define an explicit repository to work on by either label or path.", required = false)
|
2024-08-27 21:21:21 +02:00
|
|
|
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).")
|
2024-08-23 13:04:27 +02:00
|
|
|
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.")
|
2024-08-27 21:21:21 +02:00
|
|
|
flag("-v","--version",help="Shows the current norg version.")
|
2024-08-16 17:40:24 +02:00
|
|
|
try:
|
|
|
|
var opts = p.parse(commandLineParams())
|
|
|
|
norg_args.config_file = opts.config
|
2024-08-18 16:43:11 +02:00
|
|
|
norg_args.extract_destination = opts.destination
|
2024-08-23 13:04:27 +02:00
|
|
|
norg_args.command = opts.command.toCommand()
|
|
|
|
norg_args.repository = opts.repository
|
2024-08-23 15:08:14 +02:00
|
|
|
norg_args.archive = opts.archive
|
2024-08-23 16:46:35 +02:00
|
|
|
norg_args.stats = opts.stats
|
2024-08-23 13:04:27 +02:00
|
|
|
norg_args.further_args = opts.further_args
|
2024-08-27 21:21:21 +02:00
|
|
|
norg_args.show_version = opts.version
|
2024-08-16 17:40:24 +02:00
|
|
|
except ShortCircuit as err:
|
|
|
|
if err.flag == "argparse_help":
|
|
|
|
echo err.help
|
|
|
|
quit(1)
|
|
|
|
except UsageError:
|
|
|
|
echo p.help
|
|
|
|
stderr.writeLine getCurrentExceptionMsg()
|
|
|
|
quit(1)
|