Ejemplo n.º 1
0
def resolve_argv():
    if len(sys.argv) == 1 or (sys.argv[1] in args.available_commands(MOD)) or sys.argv[1].startswith("-"):
        command_plus_args = sys.argv[1:]
        mod = MOD
        default_command = DEFAULT_COMMAND

    else:
        if ":" in sys.argv[1]:
            alias, subcommand = sys.argv[1].split(":")
        else:
            alias, subcommand = sys.argv[1], ''

        try:
            cmd = dexy.plugin.Command.create_instance(alias)
        except dexy.exceptions.NoPlugin:
            msg = "No command '%s' available. Run `dexy help` to see list of available commands.\n"
            msgargs = (alias)
            sys.stderr.write(msg % msgargs)
            sys.exit(1)

        mod_name = cmd.__module__
        mod = args.load_module(mod_name)
    
        if cmd.DEFAULT_COMMAND:
            default_command = cmd.DEFAULT_COMMAND
        else:
            default_command = cmd.NAMESPACE

        command_plus_args = [subcommand] + sys.argv[2:]

    return command_plus_args, mod, default_command
Ejemplo n.º 2
0
def run():
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    try:
        if len(sys.argv) == 1 or (sys.argv[1] in args.available_commands(MOD)):
            args.parse_and_run_command(sys.argv[1:],
                                       MOD,
                                       default_command=DEFAULT_COMMAND)
        else:
            if ":" in sys.argv[1]:
                command, subcommand = sys.argv[1].split(":")
            else:
                command = sys.argv[1]
                subcommand = ""

            command_class = dexy.plugin.Command.aliases.get(command)
            mod_name = command_class.__module__
            mod = args.load_module(mod_name)

            if hasattr(command_class, 'DEFAULT_COMMAND'):
                default_command = command_class.DEFAULT_COMMAND
            else:
                default_command = command_class.NAMESPACE

            # TODO improve error message if not a valid command...
            args.parse_and_run_command([subcommand] + sys.argv[2:],
                                       mod,
                                       default_command=default_command)

    except dexy.exceptions.UserFeedback as e:
        sys.stderr.write(e.message)
        if not e.message.endswith("\n"):
            sys.stderr.write("\n")
        sys.exit(1)
Ejemplo n.º 3
0
def run():
    warnings.filterwarnings("ignore",category=DeprecationWarning)
    try:
        if len(sys.argv) == 1 or (sys.argv[1] in args.available_commands(MOD)):
            args.parse_and_run_command(sys.argv[1:], MOD, default_command=DEFAULT_COMMAND)
        else:
            if ":" in sys.argv[1]:
                command, subcommand = sys.argv[1].split(":")
            else:
                command = sys.argv[1]
                subcommand = ""

            command_class = dexy.plugin.Command.aliases.get(command)
            mod_name = command_class.__module__
            mod = args.load_module(mod_name)

            if hasattr(command_class, 'DEFAULT_COMMAND'):
                default_command = command_class.DEFAULT_COMMAND
            else:
                default_command = command_class.NAMESPACE

            # TODO improve error message if not a valid command...
            args.parse_and_run_command([subcommand] + sys.argv[2:], mod, default_command=default_command)

    except dexy.exceptions.UserFeedback as e:
        sys.stderr.write(e.message)
        if not e.message.endswith("\n"):
            sys.stderr.write("\n")
        sys.exit(1)
Ejemplo n.º 4
0
def run():
    """
    Method that runs the command specified on the command line.

    Ensures that UserFeedback exceptions are handled nicely so end users don't see tracebacks.
    """
    logging.captureWarnings(True)

    if len(sys.argv) == 1 or (sys.argv[1] in args.available_commands(MOD)) or sys.argv[1].startswith("-"):
        args.parse_and_run_command(sys.argv[1:], MOD, default_command=DEFAULT_COMMAND)
    else:
        if ":" in sys.argv[1]:
            command, subcommand = sys.argv[1].split(":")
        else:
            command = sys.argv[1]
            subcommand = ""

        command_class = dexy.plugin.Command.aliases.get(command)

        if not command_class:
            args.parse_and_run_command(subcommand, dexy.commands)

        mod_name = command_class.__module__
        mod = args.load_module(mod_name)

        if command_class.DEFAULT_COMMAND:
            default_command = command_class.DEFAULT_COMMAND
        else:
            default_command = command_class.NAMESPACE

        args.parse_and_run_command([subcommand] + sys.argv[2:], mod, default_command=default_command)
Ejemplo n.º 5
0
def resolve_argv():
    """
    Do some processing of the user-provided arguments in argv before they go to
    modargs so we can support commands defined in plugins.
    """
    only_one_arg = len(sys.argv) == 1
    second_arg_is_known_cmd = not only_one_arg and sys.argv[1] in args.available_commands(dexy_cmd_mod)
    second_arg_is_option = not only_one_arg and sys.argv[1].startswith("-")

    if only_one_arg or second_arg_is_known_cmd or second_arg_is_option:
        return sys.argv[1:], dexy_cmd_mod, dexy_default_cmd

    else:
        cmd, subcmd, cmd_mod = resolve_plugin_cmd(sys.argv[1])
        default_cmd = cmd.default_cmd or cmd.namespace
        return [subcmd] + sys.argv[2:], cmd_mod, default_cmd
Ejemplo n.º 6
0
def resolve_argv():
    """
    Do some processing of the user-provided arguments in argv before they go to
    modargs so we can support commands defined in plugins.
    """
    only_one_arg = (len(sys.argv) == 1)
    second_arg_is_known_cmd = not only_one_arg and \
        sys.argv[1] in args.available_commands(dexy_cmd_mod)
    second_arg_is_option = not only_one_arg and \
        sys.argv[1].startswith("-")

    if only_one_arg or second_arg_is_known_cmd or second_arg_is_option:
        return sys.argv[1:], dexy_cmd_mod, dexy_default_cmd

    else:
        cmd, subcmd, cmd_mod = resolve_plugin_cmd(sys.argv[1])
        default_cmd = cmd.default_cmd or cmd.namespace
        return [subcmd] + sys.argv[2:], cmd_mod, default_cmd
Ejemplo n.º 7
0
def help_command(**options):
    """
    Prints out help for the commands. 

    salmon help

    You can get help for one command with:

    salmon help -for STR
    """
    if "for" in options:
        help_text = args.help_for_command(salmon.commands, options['for'])
        if help_text:
            print help_text
        else:
            args.invalid_command_message(salmon.commands, exit_on_error=True)
    else:
        print "Available commands:\n"
        print ", ".join(args.available_commands(salmon.commands))
        print "\nUse salmon help -for <command> to find out more."
Ejemplo n.º 8
0
def help_command(**options):
    """
    Prints out help for the commands. 

    salmon help

    You can get help for one command with:

    salmon help -for STR
    """
    if "for" in options:
        help_text = args.help_for_command(salmon.commands, options['for'])
        if help_text:
            print help_text
        else:
            args.invalid_command_message(salmon.commands, exit_on_error=True)
    else:
        print "Available commands:\n"
        print ", ".join(args.available_commands(salmon.commands))
        print "\nUse salmon help -for <command> to find out more."
Ejemplo n.º 9
0
def available_commands():
    return args.available_commands(MOD)
Ejemplo n.º 10
0
from modargs import args
from ordereddict import OrderedDict
import dexy.commands
import json

commands_and_help = OrderedDict()
for cmd in args.available_commands(dexy.commands):
    help_text = args.help_text('dexy', dexy.commands, 'dexy', on=cmd)
    commands_and_help[cmd] = help_text

with open("dexy--commands.json", "w") as f:
    json.dump(commands_and_help, f)
def test_available_commands():
    assert args.available_commands(commands).index('test') >= 0, 'no help command'
Ejemplo n.º 12
0
def test_available_commands():
    assert args.available_commands(commands).index(
        'test') >= 0, 'no help command'