Sublime Forum

Unexpected keyword in sublime text 3 when using a package command

#1

Introduction

I am developping a sublime text 3 package.

Suddenly, the command I am adding the the package broke. It throws every time the following error in the console:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\Lib\python33\sublime_plugin.py", line 1456, in run_
    return self.run(**args)
TypeError: run() got an unexpected keyword argument 'redeploy_module'

This appears in “dirty” sublime as well as in clean state.

This happens when I add a list input handler.

This works

class ProjectNameInputHandler(sublime_plugin.TextInputHandler):
    def placeholder(self):
        return "Project's name - must already exist"

    # def next_input(self, args):
    #     if 'module' not in args:
    #         return RedeployModuleInputHandler()


# class RedeployModuleInputHandler(sublime_plugin.ListInputHandler):
#     def placeholder(self):
#         return "Module to create template for"

#     def list_items(self):
#         return [("Manager (v1)", "manager"),
#                 ("Projects (v2)", "projects")]


class RedeployJobCommand(sublime_plugin.WindowCommand):
    def run(self, project_name):

        plugin_path = str(os.path.dirname(__file__))
        template_cli = "\"{}\\template-python-cli\\cli.py\""\
            .format(plugin_path)

        folder = self.window.extract_variables()['folder']
        args = "redeployJob {}".format(project_name)
        command = "echo 'python {} {}'".format(template_cli, args)
        self.window.run_command("exec", {
            "shell_cmd": command,
            "working_dir": folder
        })

    def input(self, args):
        if 'project_name' not in args:
            return ProjectNameInputHandler()
        # elif 'module' not in args:
        #     return RedeployModuleInputHandler()

This does not work

import sublime_plugin
import os


class ProjectNameInputHandler(sublime_plugin.TextInputHandler):
    def placeholder(self):
        return "Project's name - must already exist"

    def next_input(self, args):
        if 'module' not in args:
            return RedeployModuleInputHandler()


class RedeployModuleInputHandler(sublime_plugin.ListInputHandler):
    def placeholder(self):
        return "Module to create template for"

    def list_items(self):
        return [("Manager (v1)", "manager"),
                ("Projects (v2)", "projects")]


class RedeployJobCommand(sublime_plugin.WindowCommand):
    def run(self, project_name, module):

        plugin_path = str(os.path.dirname(__file__))
        template_cli = "\"{}\\template-python-cli\\cli.py\""\
            .format(plugin_path)

        folder = self.window.extract_variables()['folder']
        args = "redeployJob {}".format(project_name)
        command = "echo 'python {} {}'".format(template_cli, args)
        self.window.run_command("exec", {
            "shell_cmd": command,
            "working_dir": folder
        })

    def input(self, args):
        if 'project_name' not in args:
            return ProjectNameInputHandler()
        elif 'module' not in args:
            return RedeployModuleInputHandler()

It throws the error described in the introduction.

I do not understand why it does that. What I am doing wrong ?

0 Likes

#2

What happens if you rename module here to redeploy_module ?

`

0 Likes

#3

That was the mistake !

The output of RedeployModuleInputHandler is given back as redeploy_module I guess (SomeTextTotoInputHandler output is generated like so: some_text_toto, am I right or is it just a coincidence ?

0 Likes

#4

The name of the Input Handler subclass is used by Sublime to determine what the name of the argument it represents is; RedeployModuleInputHandler becomes redeploy_module_input_handler which becomes redeploy_module; the name that will be used for the command argument.

The class either needs to be named the same as your expected command argument OR implement the name() method to change the default. However one would normally name it based on the argument and only implement name() if you’re going to re-use the same handler for multiple arguments.

1 Like