#! /Users/mohitjandwani/anaconda3/bin/python
import os
import click

@click.command()
@click.option('--tmux',default='1',help='use tmux')
@click.option('--ts', default='def', help='tmux session name')
@click.option('--vpc', default='app', help='vpc user or app')
def jump(tmux,ts,vpc):
    ip = 'i1' if vpc == 'app' else 'i2'
    if tmux == '1':
        cmd = 'ssh -t mohitkumar@{0} tmux attach -t {1}'.format(ip,ts)
    elif tmux == '3':
        cmd = 'ssh mohitkumar@{}'.format(ip)
    else:
        cmd = 'ssh -t mohitkumar@{0} tmux new -s {1}'.format(ip,ts)
    os.system(cmd)

@click.command()
@click.option('-s',help='server name')
@click.option('--vpc',default='app',help='vpc of server')
def goto(s,vpc):
    dns = s + '.ip.com'
    ip = 'i1' if vpc == 'app' else 'i2'
    cmd = 'ssh -t mohitkumar@{0} ssh {1}'.format(ip,dns)
    os.system(cmd)

@click.command()
@click.option('-c',help='server name')
def api(c):
    if c == 'dev':
        cmd = 'bundle exec middleman server'
    elif c == 'build':
        cmd = 'bundle exec middleman build --clean'
    else:
        cmd = 'ps -ef | grep "middleman"'
    os.system(cmd)


@click.command()
@click.option('-h',help='host')
@click.option('-s',help='source path')
@click.option('-d',help='destination path')
def fu(h,s,d):
    cmd = 'scp -o ProxyCommand="ssh mohitkumar@l1 nc {0} 22" {1} mohitkumar@{0}:{2}'.format(h,s,d)
    print(cmd)
    os.system(cmd)

@click.group()
def main():
    pass

main.add_command(jump)
main.add_command(goto)
main.add_command(api)
main.add_command(fu)

if __name__ == "__main__":
    main()
