eoptasks: add --list-commands argument

This commit is contained in:
Frédéric Péters 2021-01-23 19:11:32 +01:00
parent 1514d5da2b
commit d2cad4f97a
1 changed files with 22 additions and 10 deletions

View File

@ -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)