From fee10f13434256b9d85e8906f3efab93e8fc700a Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Fri, 29 Jan 2016 18:51:35 +0000 Subject: [PATCH] Using python3-docopt to process command-line arguments. Lost the color and result statuses in the command-line help, but should be able to get them back. --- golden-files/help | 28 ++++++++++++++-------------- install-dependencies | 2 +- vigil | 28 ++++++++++++++++------------ 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/golden-files/help b/golden-files/help index ee0f6d4..095025c 100644 --- a/golden-files/help +++ b/golden-files/help @@ -12,9 +12,14 @@ │The reports are cached in a directory │ │  │ │  │ -│Usage: vigil  │ +│Usage:  │ +│ vigil  │ │  │ -│e.g. # vigil my_project  │ +│Example:  │ +│ # vigil my_project  │ +│  │ +│Options:  │ +│ -h, --help Show this screen and ex │ │  │ │Keys:  │ │ h - Show the help screen. (toggle)  │ @@ -24,17 +29,12 @@ │ t - Turn the result pane to portrai │ │ l - Show the activity log. (toggle) │ │ n - Move to the next issue.  │ -│ N - Move to the next issue of the c │ -│ o - Order files by type, or by dire │ -│ p - Pause work. (toggle)  │ -│ s - Change the appearance of result │ -│ q - Quit.  │ -│  │ -│Statuses:  │ -│  Normal  │ -│   Ok  │ -│   Problem │ -│   Not applicable │ -│   Running │ +│ N - Move to the next issue of the c │ +│ o - Order files by type, or by dire │ +│ p - Pause work. (toggle) │ +│ s - Change the appearance of result │ +│ q - Quit. │ +│ │ +│Statuses: │ │  │ └──────────────────────────────────────┘ \ No newline at end of file diff --git a/install-dependencies b/install-dependencies index 920c548..4f4c0fb 100755 --- a/install-dependencies +++ b/install-dependencies @@ -6,7 +6,7 @@ set -e echo "Install the dependencies of the vigil script..." sudo apt-get --yes install python3-minimal python3-pygments python3-pyinotify \ - python3-urwid python3-psutil + python3-urwid python3-psutil python3-docopt echo echo "Install all the tools vigil may need..." ./install-tools diff --git a/vigil b/vigil index a7a5be9..1193735 100755 --- a/vigil +++ b/vigil @@ -18,9 +18,14 @@ to date. The reports are cached in a directory ".vigil" under the target directory. -Usage: vigil +Usage: + vigil -e.g. # vigil my_project +Example: + # vigil my_project + +Options: + -h, --help Show this screen and exit. Keys: *h - Show the help screen. (toggle) @@ -55,6 +60,7 @@ import threading import time import traceback +import docopt import pyinotify import fill3 @@ -1055,13 +1061,11 @@ def manage_cache(root_path): if __name__ == "__main__": - if len(sys.argv) == 2: - subprocess.call(["sudo", "-p", "Vigil needs sudo to create the filesy" - "stem sandbox... [sudo] password for %u: ", "true"]) - root_path = os.path.abspath(sys.argv[1]) - with terminal.console_title("vigil: " + os.path.basename(root_path)): - manage_cache(root_path) - with chdir(root_path): # FIX: Don't change directory if possible. - main(root_path) - else: - print(_get_help_text()) + arguments = docopt.docopt(__doc__.replace("*", "")) + root_path = os.path.abspath(arguments[""]) + subprocess.call(["sudo", "-p", "Vigil needs sudo to create the filesy" + "stem sandbox... [sudo] password for %u: ", "true"]) + with terminal.console_title("vigil: " + os.path.basename(root_path)): + manage_cache(root_path) + with chdir(root_path): # FIX: Don't change directory if possible. + main(root_path)