summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2021-01-23 18:11:32 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2021-01-30 19:59:09 (GMT)
commit868b870979ea730c07f3f4eb384c02aa8127f90a (patch)
tree989924e3366af82ff82ea517cf6b8eea8d15b410
parentf257f25a2e7dd1d6c63f94c7b85f16206a4b5b4a (diff)
downloadeoptasks-868b870979ea730c07f3f4eb384c02aa8127f90a.zip
eoptasks-868b870979ea730c07f3f4eb384c02aa8127f90a.tar.gz
eoptasks-868b870979ea730c07f3f4eb384c02aa8127f90a.tar.bz2
add --list-commands argument
-rwxr-xr-xeoptasks.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/eoptasks.py b/eoptasks.py
index 7c6f882..781f1ad 100755
--- a/eoptasks.py
+++ b/eoptasks.py
@@ -99,6 +99,7 @@ def parse_args():
parser.add_argument('--command-window', action='store_true')
parser.add_argument('--command-server-name', dest='command_server_name', type=str)
parser.add_argument('--noinput', dest='noinput', action='store_true')
+ parser.add_argument('--list-commands', dest='list_commands', action='store_true')
parser.add_argument('-k', dest='keywords', type=str)
parser.add_argument('-x', dest='exclude', type=str)
parser.add_argument('cmd', type=str, nargs='?', default=None)
@@ -203,12 +204,8 @@ def send_status_message(tmux_session_name, msg):
sock.close()
-def command_window(args):
- config = configparser.ConfigParser()
- config.read(os.path.join(os.path.expanduser('~/.config/eoptasks.ini')))
-
- tmux_session_name = args.session_name
- builtin_cmds = {
+def get_commands():
+ commands = {
'apt.update': 'sudo apt update',
'apt.upgrade': 'sudo apt update && sudo apt full-upgrade -y',
# collectstatic is useful after an upgrade of gadjo.
@@ -239,10 +236,19 @@ def command_window(args):
# puppet.update, unfortunately without proper error checking.
'puppet.update': '''sudo puppet agent -t || true''',
}
- if config.has_section('command:%s' % args.cmd):
- cmd = config.get('command:%s' % args.cmd, 'cmd')
- elif args.cmd in builtin_cmds:
- cmd = builtin_cmds[args.cmd]
+ config = configparser.ConfigParser()
+ config.read(os.path.join(os.path.expanduser('~/.config/eoptasks.ini')))
+ for section in config.sections():
+ if section.startswith('command:'):
+ commands[section[len('command:') :]] = config.get(section, 'cmd')
+ return commands
+
+
+def command_window(args):
+ tmux_session_name = args.session_name
+ commands = get_commands()
+ if args.cmd in commands:
+ cmd = commands[args.cmd]
else:
cmd = args.cmd
@@ -275,6 +281,12 @@ def command_window(args):
args = parse_args()
+if args.list_commands:
+ commands = get_commands()
+ for command in sorted(commands):
+ print(command)
+ sys.exit(0)
+
if args.status_window:
status_window(args)
sys.exit(0)