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 ../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
|
||||
|
|
|
@ -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():
|
||||
|
|
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 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
|
||||
|
|
|
@ -8,6 +8,7 @@ import utils/actions
|
|||
proc start() =
|
||||
parseArgs()
|
||||
norg_config.args = norg_args
|
||||
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)
|
||||
|
|
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