diff --git a/dsync b/dsync index e77c21c..16749c7 100644 --- a/dsync +++ b/dsync @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +VERSION = "0.1.0" + import sys import json import subprocess @@ -404,23 +406,24 @@ def list_nodes(): def show_help(): help_text = """ -dsync.py - Directory Synchronization Tool +dsync - Directory Synchronization Tool Usage: - dsync.py init Initialize dsync in current directory - dsync.py add-node [node2...] Add one or more nodes - dsync.py del-node [node2...] Remove one or more nodes - dsync.py list-nodes List all configured nodes - dsync.py status Show sync status for all nodes - dsync.py sync Sync to all configured nodes - dsync.py help Show this help message + dsync init Initialize dsync in current directory + dsync add-node [node2...] Add one or more nodes + dsync del-node [node2...] Remove one or more nodes + dsync list-nodes List all configured nodes + dsync status Show sync status for all nodes + dsync sync Sync to all configured nodes + dsync help Show this help message + dsync version Print dsync version Examples: - dsync.py init - dsync.py add-node user@server1.com user@server2.com - dsync.py del-node user@server1.com - dsync.py status - dsync.py sync + dsync init + dsync add-node user@server1.com user@server2.com + dsync del-node user@server1.com + dsync status + dsync sync Notes: - Status command shows pending changes without syncing @@ -430,6 +433,11 @@ Notes: """ print(help_text) +def show_version(): + """Print dsync version.""" + print(f"dsync {VERSION}") + + if __name__ == "__main__": if len(sys.argv) < 2: show_help() @@ -439,24 +447,27 @@ if __name__ == "__main__": if cmd == "init": init() - elif cmd == "add-node": + elif cmd in ("-an", "--add-node", "add-node"): if len(sys.argv) < 3: print(colored("Usage: dsync.py add-node [node2...]", Colors.RED)) sys.exit(1) add_nodes(*sys.argv[2:]) - elif cmd == "del-node": + elif cmd in ("-dn", "--del-node", "del-node"): if len(sys.argv) < 3: print(colored("Usage: dsync.py del-node [node2...]", Colors.RED)) sys.exit(1) del_nodes(*sys.argv[2:]) - elif cmd == "list-nodes": + elif cmd in ("-ln", "--list-nodes", "list-nodes"): list_nodes() elif cmd == "status": status() elif cmd == "sync": sync() - elif cmd == "help": + elif cmd in ("-h", "--help", "help"): show_help() + elif cmd in ("-v", "--version", "version"): + show_version() + sys.exit(0) else: print(colored(f"Unknown command: {cmd}", Colors.RED)) show_help()