diff options
author | xengineering <me@xengineering.eu> | 2021-09-04 09:52:47 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2021-09-04 09:52:47 +0200 |
commit | 48a2e73883d52236b76d4988a335b4752dd137da (patch) | |
tree | b34fe8d87b9ffc47ad1876c79eb9ad867c3698bc /src | |
parent | 96200dfe5fd92e62936f2aa6fc1ec57afc1c5bbe (diff) | |
download | xbackup-48a2e73883d52236b76d4988a335b4752dd137da.tar xbackup-48a2e73883d52236b76d4988a335b4752dd137da.tar.zst xbackup-48a2e73883d52236b76d4988a335b4752dd137da.zip |
Implement Argument Parsing
Diffstat (limited to 'src')
-rw-r--r-- | src/xbackup/script.py | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/xbackup/script.py b/src/xbackup/script.py index 198b6b3..9424b83 100644 --- a/src/xbackup/script.py +++ b/src/xbackup/script.py @@ -6,10 +6,46 @@ import argparse +import time +import sys def run(): """runs xbackup script functionality""" - parser = argparse.ArgumentParser() - parser.parse_args() + args = parse_arguments() + + if args.command == "backup": + print("Performing dummy backup based on '{}'".format(args.config)) + time.sleep(1) + print("Done!") + else: + print("Unknown command '{}'".format(args.command)) + sys.exit(1) + +def parse_arguments(): + """handles argument parsing with the argparse module""" + + # parser creation + parser = argparse.ArgumentParser( + prog="xbackup", + description="xbackup CLI Script to make a File-based full System Backup", + epilog="Project page: https://gitea.xengineering.eu/xengineering/xbackup", + ) + + # positional arguments + parser.add_argument("command", type=str, + help="the action to be performed", + choices=["backup"], + ) + + # optional arguments + parser.add_argument("-c", "--config", type=str, + metavar="CONFIG", + help="path to the JSON configuration file", + default="/etc/xbackup/config.json", + ) + + # argument parsing + args = parser.parse_args() + return args |