2024-08-16 17:40:24 +02:00
|
|
|
import argparse
|
2024-08-18 19:45:37 +02:00
|
|
|
import ../model/borg_type
|
2024-08-16 17:40:24 +02:00
|
|
|
|
|
|
|
type
|
|
|
|
NorgArgs* = object
|
|
|
|
config_file*: string
|
2024-08-18 16:43:11 +02:00
|
|
|
extract_destination*: string
|
2024-08-18 19:45:37 +02:00
|
|
|
borg_cmd*: BorgCommand
|
2024-08-16 17:40:24 +02:00
|
|
|
others*: seq[string]
|
|
|
|
|
|
|
|
var norg_args*: NorgArgs = NorgArgs()
|
|
|
|
|
|
|
|
proc parseArgs*() =
|
|
|
|
var p = newParser:
|
2024-08-18 17:13:10 +02:00
|
|
|
help("Norg\r\nA portable borg backup wrapper utility")
|
2024-08-16 17:40:24 +02:00
|
|
|
option("-c", "--config", help="Config file to use", required = true)
|
2024-08-18 16:43:11 +02:00
|
|
|
option("-d", "--destination", help="Destination when extracting backup", required = false)
|
|
|
|
arg("borg_cmd", default=some("list"))
|
2024-08-16 17:40:24 +02:00
|
|
|
arg("others", nargs = -1)
|
|
|
|
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-18 19:45:37 +02:00
|
|
|
norg_args.borg_cmd = opts.borg_cmd.toBorgCommand()
|
2024-08-16 17:40:24 +02:00
|
|
|
norg_args.others = opts.others
|
|
|
|
|
|
|
|
except ShortCircuit as err:
|
|
|
|
if err.flag == "argparse_help":
|
|
|
|
echo err.help
|
|
|
|
quit(1)
|
|
|
|
except UsageError:
|
|
|
|
echo p.help
|
|
|
|
stderr.writeLine getCurrentExceptionMsg()
|
|
|
|
quit(1)
|