added version flag to command line output
This commit is contained in:
parent
92392f9796
commit
c8933f9b09
6 changed files with 45 additions and 16 deletions
|
@ -1,28 +1,19 @@
|
||||||
import argparse
|
import argparse
|
||||||
import ../model/command_type
|
import ../model/config_type
|
||||||
|
|
||||||
type
|
var norg_args*: NorgArgs = newNorgArgs()
|
||||||
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()
|
|
||||||
|
|
||||||
proc parseArgs*() =
|
proc parseArgs*() =
|
||||||
var p = newParser:
|
var p = newParser:
|
||||||
help("Norg\r\nA portable borg backup wrapper utility")
|
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("-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")
|
||||||
try:
|
try:
|
||||||
var opts = p.parse(commandLineParams())
|
var opts = p.parse(commandLineParams())
|
||||||
norg_args.config_file = opts.config
|
norg_args.config_file = opts.config
|
||||||
|
@ -32,6 +23,9 @@ 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:
|
||||||
|
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
|
||||||
|
|
|
@ -3,12 +3,15 @@ import parsetoml
|
||||||
import ../model/config_type
|
import ../model/config_type
|
||||||
import ../model/command_type
|
import ../model/command_type
|
||||||
import ../model/encryption_type
|
import ../model/encryption_type
|
||||||
|
import ../model/args_type
|
||||||
import notifier_config
|
import notifier_config
|
||||||
import actions_config
|
import actions_config
|
||||||
import maintenance_config
|
import maintenance_config
|
||||||
|
export args_type
|
||||||
|
|
||||||
export config_type
|
export config_type
|
||||||
|
|
||||||
|
|
||||||
proc parseSourceDirectories*(in_conf: TomlValueRef): seq[string] =
|
proc parseSourceDirectories*(in_conf: TomlValueRef): seq[string] =
|
||||||
var src_dirs: seq[string] = @[]
|
var src_dirs: seq[string] = @[]
|
||||||
for dir in in_conf{"source_directories"}.getElems():
|
for dir in in_conf{"source_directories"}.getElems():
|
||||||
|
|
18
norg/model/args_type.nim
Normal file
18
norg/model/args_type.nim
Normal file
|
@ -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
|
||||||
|
|
|
@ -3,14 +3,17 @@ import notifier_types
|
||||||
import actions_type
|
import actions_type
|
||||||
import maintenance_type
|
import maintenance_type
|
||||||
import binary_type
|
import binary_type
|
||||||
import ../config/args
|
import args_type
|
||||||
|
|
||||||
export repository_type
|
export repository_type
|
||||||
export notifier_types
|
export notifier_types
|
||||||
export actions_type
|
export actions_type
|
||||||
export maintenance_type
|
export maintenance_type
|
||||||
export binary_type
|
export binary_type
|
||||||
|
export args_type
|
||||||
|
|
||||||
|
import ../utils/version
|
||||||
|
const VERSION*: string = getVersion()
|
||||||
|
|
||||||
type
|
type
|
||||||
NorgConfig* = ref object
|
NorgConfig* = ref object
|
||||||
|
|
|
@ -8,6 +8,7 @@ import utils/actions
|
||||||
proc start() =
|
proc start() =
|
||||||
parseArgs()
|
parseArgs()
|
||||||
norg_config.args = norg_args
|
norg_config.args = norg_args
|
||||||
|
if 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)
|
||||||
|
|
10
norg/utils/version.nim
Normal file
10
norg/utils/version.nim
Normal file
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue