summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmonitor-menu.py38
1 files changed, 28 insertions, 10 deletions
diff --git a/monitor-menu.py b/monitor-menu.py
index 423faee..c81f753 100755
--- a/monitor-menu.py
+++ b/monitor-menu.py
@@ -1,8 +1,16 @@
#!/usr/bin/env python3
+'''
+monitor-menu.py
+Usage:
+ monitor-menu.py
+ monitor-menu.py <profile>
+'''
+
from os.path import expanduser
import dialog
+import docopt
import json
import subprocess
@@ -13,18 +21,19 @@ class MonitorMenu():
with open(expanduser(config_file)) as fd:
self.profiles = json.load(fd)
- def run(self):
+ def run(self, profile_idx=None):
choices = []
- i = 0
- for p in self.profiles:
- choices.append((str(i), p['name']))
- i += 1
+ if profile_idx is None:
+ i = 0
+ for p in self.profiles:
+ choices.append((str(i), p['name']))
+ i += 1
- code, profile_idx = d.menu('Select the profile you want to use.', choices=choices)
+ code, profile_idx = d.menu('Select the profile you want to use.', choices=choices)
- if code == d.ESC or code == d.CANCEL:
- return
+ if code == d.ESC or code == d.CANCEL:
+ return
profile = self.profiles[int(profile_idx)]
@@ -47,10 +56,19 @@ class MonitorMenu():
subprocess.run(feh_cmd)
-def main():
+def main(argv=None):
+ args = docopt.docopt(__doc__, version='1', argv=argv)
+
menu = MonitorMenu()
- menu.run()
+ try:
+ if '<profile>' in args:
+ menu.run(int(args['<profile>']))
+ else:
+ menu.run()
+
+ except ValueError as e:
+ raise docopt.DocoptExit(str(e))
if __name__ == '__main__':
main()