Добавлены дополнительные ключи для флагов

main
ilyukhin 2 months ago
parent 463c0dcd1b
commit 5e0ef35744

45
dsync

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

Loading…
Cancel
Save