eoptasks: add --list-commands argument
This commit is contained in:
parent
1514d5da2b
commit
d2cad4f97a
|
@ -121,6 +121,7 @@ def parse_args():
|
||||||
parser.add_argument('--command-window', action='store_true')
|
parser.add_argument('--command-window', action='store_true')
|
||||||
parser.add_argument('--command-server-name', dest='command_server_name', type=str)
|
parser.add_argument('--command-server-name', dest='command_server_name', type=str)
|
||||||
parser.add_argument('--noinput', dest='noinput', action='store_true')
|
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('-k', dest='keywords', type=str)
|
||||||
parser.add_argument('-x', dest='exclude', type=str)
|
parser.add_argument('-x', dest='exclude', type=str)
|
||||||
parser.add_argument('cmd', type=str, nargs='?', default=None)
|
parser.add_argument('cmd', type=str, nargs='?', default=None)
|
||||||
|
@ -224,12 +225,8 @@ def send_status_message(tmux_session_name, msg):
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
|
|
||||||
def command_window(args):
|
def get_commands():
|
||||||
config = configparser.ConfigParser()
|
commands = {
|
||||||
config.read(os.path.join(os.path.expanduser('~/.config/eoptasks.ini')))
|
|
||||||
|
|
||||||
tmux_session_name = args.session_name
|
|
||||||
builtin_cmds = {
|
|
||||||
'apt.update': 'sudo apt update',
|
'apt.update': 'sudo apt update',
|
||||||
'apt.upgrade': 'sudo apt update && sudo apt full-upgrade -y',
|
'apt.upgrade': 'sudo apt update && sudo apt full-upgrade -y',
|
||||||
# collectstatic is useful after an upgrade of gadjo.
|
# 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, unfortunately without proper error checking.
|
||||||
'puppet.update': '''sudo puppet agent -t || true''',
|
'puppet.update': '''sudo puppet agent -t || true''',
|
||||||
}
|
}
|
||||||
if config.has_section('command:%s' % args.cmd):
|
config = configparser.ConfigParser()
|
||||||
cmd = config.get('command:%s' % args.cmd, 'cmd')
|
config.read(os.path.join(os.path.expanduser('~/.config/eoptasks.ini')))
|
||||||
elif args.cmd in builtin_cmds:
|
for section in config.sections():
|
||||||
cmd = builtin_cmds[args.cmd]
|
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:
|
else:
|
||||||
cmd = args.cmd
|
cmd = args.cmd
|
||||||
|
|
||||||
|
@ -293,6 +299,12 @@ def command_window(args):
|
||||||
|
|
||||||
args = parse_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:
|
if args.status_window:
|
||||||
status_window(args)
|
status_window(args)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
Loading…
Reference in New Issue