#!/usr/bin/env python
import sys
import re
from subprocess import call


file_path = None
try:
    from littlechef import littlechef
    file_path = re.sub(r'\.pyc$', '.py', littlechef.__file__)
except ImportError:
    print("Little Chef was not correctly installed: Couldn't import littlechef.py")
    sys.exit(1)

# Act on some arguments and pass the rest to fabric
args = ['fab', '-f', file_path]
if len(sys.argv) > 1:
    for arg in sys.argv[1:]:
        if arg == '-v' or arg == '-V' or arg == '--version':
            print('LittleChef {0}'.format(littlechef.version))
            sys.argv.remove(arg)
            sys.exit(0)
        else:
            args.append(arg)
else:
    sys.exit("No order given. Type 'cook -l' for a list of orders\n")

# Call fabric with the given arguments
call(args)
