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-23 18:11:32 (GMT)
commitd2cad4f97ac5ca45e3fb6a789344789164a53681 (patch)
tree2c85cf92db5a5e64e66592595ee4e18dce4ad4b5
parent1514d5da2bd6c52f2baa5070c805b6bd6036f916 (diff)
downloadmisc-fred-d2cad4f97ac5ca45e3fb6a789344789164a53681.zip
misc-fred-d2cad4f97ac5ca45e3fb6a789344789164a53681.tar.gz
misc-fred-d2cad4f97ac5ca45e3fb6a789344789164a53681.tar.bz2
eoptasks: add --list-commands argument
-rwxr-xr-xeoptasks/eoptasks.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/eoptasks/eoptasks.py b/eoptasks/eoptasks.py
index ca5f1d5..347dd90 100755
--- a/eoptasks/eoptasks.py
+++ b/eoptasks/eoptasks.py
@@ -121,6 +121,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)
@@ -224,12 +225,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.
@@ -258,10 +255,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
@@ -293,6 +299,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)