#!/home/bo/.local/share/virtualenvs/python-rc-0c6h7zm2/bin/python
import argparse
import sys
import rc

parser = argparse.ArgumentParser('rc', '''
Usage: 
rc <group name> command ...: execute command non interactively in group of machines
rc <group name>/name_pattern1,... command ...: execute command non interactively in group of machines, but only subset that match pattern 
rc <group name> @file: execute content of local file in group of machines
rc tmux <group name>: launch a tmux that ssh to every instance in group of machines, input to one machine will be replicate to the group
rc edit <group name>: create or edit machines in group
rc cat <group name>: show machines in group
rc ls: show defined groups
rc rm <group name>: delete group definition (does not delete machines)
rc rsync: parallel rsync
rc ssh-config: generate ~/.ssh/config that can be used with ssh machine_name, scp, rsync, mosh, etc.
''', 'python-rc cli, parallel execute command, download and upload files to machines')
parser.add_argument('command', help='Subcommand to run')
args = parser.parse_args(sys.argv[1:2])
if args.command in ['edit', 'cat', 'ls', 'rm', 'rsync', 'edit', 'tmux', 'ssh-config']:
    getattr(rc.cli, args.command)(sys.argv[2:])
elif rc.cli.config.get(args.command):
    rc.cli.execute(sys.argv[2:])
else:
    parser.print_usage()
    exit(2)
