Exemple #1
0
def main():
	import sys

	# os args are gained differently on win32
	try:
		from click.utils import get_os_args
		args = get_os_args()
	except ImportError:
		# for whatever reason we are running an older Click version?
		args = sys.argv[1:]

	if len(args) >= len(sys.argv):
		# Now some ugly preprocessing of our arguments starts. We have a somewhat difficult situation on our hands
		# here if we are running under Windows and want to be able to handle utf-8 command line parameters (think
		# plugin parameters such as names or something, e.g. for the "dev plugin:new" command) while at the same
		# time also supporting sys.argv rewriting for debuggers etc (e.g. PyCharm).
		#
		# So what we try to do here is solve this... Generally speaking, sys.argv and whatever Windows returns
		# for its CommandLineToArgvW win32 function should have the same length. If it doesn't however and
		# sys.argv is shorter than the win32 specific command line arguments, obviously stuff was cut off from
		# sys.argv which also needs to be cut off of the win32 command line arguments.
		#
		# So this is what we do here.

		# -1 because first entry is the script that was called
		sys_args_length = len(sys.argv) - 1

		# cut off stuff from the beginning
		args = args[-1 * sys_args_length:] if sys_args_length else []

	from octoprint.cli import octo
	octo(args=args, prog_name="octoprint", auto_envvar_prefix="OCTOPRINT")
Exemple #2
0
    def main(
        self,
        args=None,
        prog_name=None,
        complete_var=None,
        standalone_mode=True,
        **extra,
    ):
        if self._metadata:
            extra.update(obj=self._metadata)

        # This is how click's internals parse sys.argv, which include the command,
        # subcommand, arguments and options. click doesn't store this information anywhere
        # so we have to re-do it.
        # https://github.com/pallets/click/blob/master/src/click/core.py#L942-L945
        args = get_os_args() if args is None else list(args)
        self._cli_hook_manager.hook.before_command_run(  # pylint: disable=no-member
            project_metadata=self._metadata,
            command_args=args)

        super().main(
            args=args,
            prog_name=prog_name,
            complete_var=complete_var,
            standalone_mode=standalone_mode,
            **extra,
        )
Exemple #3
0
def main():
	import sys

	# os args are gained differently on win32
	try:
		from click.utils import get_os_args
		args = get_os_args()
	except ImportError:
		# for whatever reason we are running an older Click version?
		args = sys.argv[1:]

	if len(args) >= len(sys.argv):
		# Now some ugly preprocessing of our arguments starts. We have a somewhat difficult situation on our hands
		# here if we are running under Windows and want to be able to handle utf-8 command line parameters (think
		# plugin parameters such as names or something, e.g. for the "dev plugin:new" command) while at the same
		# time also supporting sys.argv rewriting for debuggers etc (e.g. PyCharm).
		#
		# So what we try to do here is solve this... Generally speaking, sys.argv and whatever Windows returns
		# for its CommandLineToArgvW win32 function should have the same length. If it doesn't however and
		# sys.argv is shorter than the win32 specific command line arguments, obviously stuff was cut off from
		# sys.argv which also needs to be cut off of the win32 command line arguments.
		#
		# So this is what we do here.

		# -1 because first entry is the script that was called
		sys_args_length = len(sys.argv) - 1

		# cut off stuff from the beginning
		args = args[-1 * sys_args_length:] if sys_args_length else []

	from octoprint.cli import octo
	octo(args=args, prog_name="octoprint", auto_envvar_prefix="OCTOPRINT")
Exemple #4
0
 def wrapper(*args, **kwargs):
     ctx = click.get_current_context()
     append = ''
     os_args = []
     for os_arg in (_args or get_os_args())[slice(*args_slice)]:
         if os_arg.startswith('-'):
             append = os_arg
         else:
             os_args.append(("{}\b".format(append), os_arg))
             append = ''
     params = {}
     defaults = {}
     for param in ctx.command.get_params(ctx):
         if param.name in options.keys():
             params[param.name] = param.opts
             defaults[param.name] = param.default
     _kwargs = {k: v for k, v in kwargs.items() if k in pairings}
     _params = {k: {} for k, v in params.items()}
     if pairings and os_args:
         index = 0
         for prefix, _ in os_args:
             if prefix.startswith('\b'):
                 index += 1
             else:
                 for name, opts in params.items():
                     if any(prefix.startswith(opt) for opt in opts):
                         kw_arg_index = len(_params[name])
                         kw_arg = kwargs[name][kw_arg_index]
                         _params[name][index - 1] = kw_arg
         for name, opts in _params.items():
             default = defaults[name] or options[name]
             _list = [default] * len(kwargs[argument])
             for k, v in opts.items():
                 _list[k] = v
             _kwargs[name] = tuple(_list)
         kwargs.update(_kwargs)
     if all(len(kwargs[opt]) == 0 for opt in options):
         for name, opts in _params.items():
             default = defaults[name] or options[name]
             _list = [default] * len(kwargs[argument])
             for k, v in opts.items():
                 _list[k] = v
             _kwargs[name] = tuple(_list)
         kwargs.update(_kwargs)
     return f(*args, **kwargs)