Example #1
0
 def external_command(**kwargs):
     from click_project.lib import call
     config.merge_settings()
     args = ([command_path] + get_settings_for_path("parameters", path))
     env = {(config.main_command.path + "___" + key).upper():
            (str(value) if value else "")
            for key, value in kwargs.items()}
     ctx = click.get_current_context()
     env[(config.main_command.path +
          "___PATH").upper()] = (ctx.command_path.replace(" ",
                                                          "_").upper())
     while ctx:
         env.update({
             (ctx.command_path.replace(" ", "_") + "__" + key).upper():
             ((" ".join(map(quote, value)) if type(value) is tuple else
               str(value) if value else ""))
             for key, value in ctx.params.items()
         })
         ctx = ctx.parent
     env[(config.main_command.path + "___CMD_OPTIND").upper()] = (str(
         len(config.command_line_settings["parameters"][path])))
     env[(config.main_command.path + "___CMD_ARGS").upper()] = (
         " ".join(
             quote(a)
             for a in config.command_line_settings["parameters"][path]))
     env[(config.main_command.path + "___OPTIND").upper()] = (str(
         len(args[1:])))
     env[(config.main_command.path + "___ARGS").upper()] = (" ".join(
         quote(a) for a in args[1:]))
     with updated_env(**env):
         call(args)
Example #2
0
 def show_parameters_callback(self, ctx, param, value):
     if value and not ctx.resilient_parsing:
         raw_args = config.command_line_settings["parameters"][self.path]
         index = raw_args.index('--show-parameters')
         raw_args = raw_args[:index] + raw_args[index + 2:]
         config.command_line_settings["parameters"][self.path] = raw_args
         config.merge_settings()
         run(["parameters"] + self.parameters_callback_split_value(value) +
             ["show", self.path])
         exit(0)
        def external_command(**kwargs):
            from click_project.lib import call
            ctx = click.get_current_context()
            config.merge_settings()
            args = ([command_path] + list(ctx.params.get("args", [])))

            def value_to_string(value):
                return (" ".join(map(quote, value)) if type(value) is tuple
                        else str(value) if value else "")

            env = {("CLK___" + key).upper(): (value_to_string(value))
                   for key, value in kwargs.items()}
            env[("CLK___PATH").upper()] = (ctx.command_path.replace(
                " ", "_").upper())
            if "args" in ctx.params:
                env[("CLK___ARGS").upper()] = " ".join(
                    map(quote, ctx.params["args"]))

            while ctx:
                env.update({
                    (ctx.command_path.replace(" ", "_") + "__" + key).upper():
                    (value_to_string(value))
                    for key, value in ctx.params.items()
                })
                ctx = ctx.parent

            for path, parameters in config.get_settings2("parameters").items():
                env[(f"CLK_P_" + path.replace("-", "__").replace(
                    ".", "_")).upper()] = " ".join(map(quote, parameters))

            env[("CLK___CMD_OPTIND").upper()] = (str(
                len(
                    config.commandline_profile.get_settings("parameters")
                    [path])))
            env[("CLK___CMD_ARGS").upper()] = (" ".join(
                quote(a) for a in config.commandline_profile.get_settings(
                    "parameters")[path]))
            env[("CLK___OPTIND").upper()] = (str(len(args[1:])))
            env[("CLK___ALL").upper()] = (" ".join(quote(a) for a in args[1:]))
            with updated_env(**env):
                call(
                    args,
                    internal=True,
                )
Example #4
0
 def set_command_line_settings(self, ctx, args):
     config.command_line_settings["parameters"][self.path] += args
     config.merge_settings()