diff --git a/python/helpers/pycharm/django_manage_commands_provider/_optparse.py b/python/helpers/pycharm/django_manage_commands_provider/_optparse.py
index 16617ab40fcb..5680b80569c6 100644
--- a/python/helpers/pycharm/django_manage_commands_provider/_optparse.py
+++ b/python/helpers/pycharm/django_manage_commands_provider/_optparse.py
@@ -24,17 +24,26 @@ def report_data(dumper):
command = utility.fetch_command(command_name)
assert isinstance(command, BaseCommand)
dumper.start_command(command_name=command_name,
- command_help_text=str(command.usage("").replace("%prog", command_name)), # TODO: support subcommands
+ command_help_text=str(command.usage("").replace("%prog", command_name)),
+ # TODO: support subcommands
command_args_text=str(command.args))
for opt in command.option_list:
- opt_type = opt.type if opt.type in Option.TYPES else "" # Empty for unknown
+ num_of_args = int(opt.nargs) if opt.nargs else 0
+ opt_type = None
+ if num_of_args > 0:
+ # If option accepts arg, we need to determine its type. It could be int, choices, or something other
+ # See https://docs.python.org/2/library/optparse.html#standard-option-types
+ if opt.type in ["int", "long"]:
+ opt_type = "int"
+ elif opt.choices:
+ assert isinstance(opt.choices, list), "Choices should be list"
+ opt_type = opt.choices
+
# There is no official way to access this field, so I use protected one. At least it is public API.
# noinspection PyProtectedMember
dumper.add_command_option(
- opt_type=opt_type,
- choices=opt.choices,
long_opt_names=opt._long_opts,
short_opt_names=opt._short_opts,
help_text=opt.help,
- num_of_args=opt.nargs)
+ argument_info=(num_of_args, opt_type) if num_of_args else None)
dumper.close_command()
\ No newline at end of file
diff --git a/python/helpers/pycharm/django_manage_commands_provider/_xml.py b/python/helpers/pycharm/django_manage_commands_provider/_xml.py
index 40260a01ab83..4f034026dd4d 100644
--- a/python/helpers/pycharm/django_manage_commands_provider/_xml.py
+++ b/python/helpers/pycharm/django_manage_commands_provider/_xml.py
@@ -6,13 +6,17 @@ It does not have schema (yet!) but here is XML format it uses.
-- root
-- info about command
-
+"option_type" is only set if "numberOfArgs" > 0, and it can be: "int" (means integer),
+"choices" (means opt can have one of the values, provided in choices) or "str" that means "string" (option may have any value)
+
Classes like DjangoCommandsInfo is used on Java side.
"""
@@ -77,35 +81,45 @@ class XmlDumper(object):
self.__command_element.setAttribute("args", command_args_text)
self.__root.appendChild(self.__command_element)
- def add_command_option(self, opt_type, choices, long_opt_names, short_opt_names, help_text, num_of_args):
+ def add_command_option(self, long_opt_names, short_opt_names, help_text, argument_info):
"""
Adds command option
- :param opt_type: "string", "int", "long", "float", "complex", "choice"
- :param choices: list of choices for "choice" type
+ :param argument_info: None if option does not accept any arguments or tuple of (num_of_args, type_info) \
+ where num_of_args is int > 0 and type_info is str, representing type (only "int" and "string" are supported) \
+ or list of available types in case of choices
+
:param long_opt_names: list of long opt names
:param short_opt_names: list of short opt names
:param help_text: help text
- :param num_of_args: number of arguments
- :type opt_type str
- :type choices list of string
:type long_opt_names list of str
:type short_opt_names list of str
:type help_text str
- :type num_of_args int
+ :type argument_info tuple
"""
assert isinstance(self.__command_element, Element), "Add option in command only"
- option = self.__document.createElement("option")
- option.setAttribute("type", opt_type)
- if choices:
- self.__create_text_array(option, "choices", choices)
+ option = self.__document.createElement("option")
+
+ opt_type_to_report = None
+ num_of_args = 0
+
+ if argument_info:
+ (num_of_args, type_info) = argument_info
+ if isinstance(type_info, list):
+ self.__create_text_array(option, "choices", type_info)
+ opt_type_to_report = "choices"
+ else:
+ opt_type_to_report = "int" if str(type_info) == "int" else "str"
+
if long_opt_names:
self.__create_text_array(option, "longNames", long_opt_names)
if short_opt_names:
self.__create_text_array(option, "shortNames", short_opt_names)
+ if opt_type_to_report:
+ option.setAttribute("type", opt_type_to_report)
option.setAttribute("help", help_text)
if num_of_args:
option.setAttribute("numberOfArgs", str(num_of_args))
diff --git a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Argument.java b/python/src/com/jetbrains/python/commandInterface/command/Argument.java
similarity index 96%
rename from python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Argument.java
rename to python/src/com/jetbrains/python/commandInterface/command/Argument.java
index fc3f64192c17..4e33c3b585e9 100644
--- a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Argument.java
+++ b/python/src/com/jetbrains/python/commandInterface/command/Argument.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.jetbrains.python.commandInterface.commandBasedChunkDriver;
+package com.jetbrains.python.commandInterface.command;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/ArgumentsInfo.java b/python/src/com/jetbrains/python/commandInterface/command/ArgumentsInfo.java
similarity index 95%
rename from python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/ArgumentsInfo.java
rename to python/src/com/jetbrains/python/commandInterface/command/ArgumentsInfo.java
index ad43da45adcd..c1eb793702e9 100644
--- a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/ArgumentsInfo.java
+++ b/python/src/com/jetbrains/python/commandInterface/command/ArgumentsInfo.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.jetbrains.python.commandInterface.commandBasedChunkDriver;
+package com.jetbrains.python.commandInterface.command;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.Nullable;
diff --git a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Command.java b/python/src/com/jetbrains/python/commandInterface/command/Command.java
similarity index 87%
rename from python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Command.java
rename to python/src/com/jetbrains/python/commandInterface/command/Command.java
index 694021964fea..2d15d152c3c1 100644
--- a/python/src/com/jetbrains/python/commandInterface/commandBasedChunkDriver/Command.java
+++ b/python/src/com/jetbrains/python/commandInterface/command/Command.java
@@ -13,15 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.jetbrains.python.commandInterface.commandBasedChunkDriver;
+package com.jetbrains.python.commandInterface.command;
import com.intellij.openapi.module.Module;
import com.jetbrains.python.commandLineParser.CommandLineParseResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.List;
+
/**
- * Command with arguments
+ * Command with arguments and options
*
* @author Ilya.Kazakevich
*/
@@ -47,6 +49,12 @@ public interface Command {
@NotNull
ArgumentsInfo getArgumentsInfo();
+ /**
+ * @return command options
+ */
+ @NotNull
+ List