def test_configuration_option(self):
     toml_provider = TomlProvider()
     click_option = configuration_option(provider=toml_provider)
     clc = click_option(self.Dummy())
     self.assertEqual(clc.__click_params__[0].is_eager, True)
     self.assertEqual(clc.__click_params__[0].help, "Read config-env from Configuration File.")
     self.assertEqual(clc.__click_params__[0].hidden, True)
     self.assertEqual(clc.__click_params__[0].expose_value, False)
     self.assertEqual(clc.__click_params__[0].callback.args, (None, "--config-env", "default", None, toml_provider))
 def test_configuration_option(self):
     toml_provider = TomlProvider()
     click_option = configuration_option(provider=toml_provider)
     clc = click_option(self.Dummy())
     self.assertEqual(clc.__click_params__[0].is_eager, True)
     self.assertEqual(
         clc.__click_params__[0].help,
         "This is a hidden click option whose callback function loads configuration parameters.",
     )
     self.assertEqual(clc.__click_params__[0].hidden, True)
     self.assertEqual(clc.__click_params__[0].expose_value, False)
     self.assertEqual(clc.__click_params__[0].callback.args, (None, None, None, toml_provider))
    def get_command(self, ctx, cmd_name):
        """
        gets the Click Commands underneath a service name

        Parameters
        ----------
        ctx: Context
            context object passed in
        cmd_name: string
            the service name
        Returns
        -------
        cmd: Click.Command
            the Click Commands that can be called from the CLI
        """

        if cmd_name not in self.subcmd_definition:
            return None
        parameters = []
        for param_name in self.subcmd_definition[cmd_name][self.TAGS].keys():
            default = self.subcmd_definition[cmd_name][
                self.TAGS][param_name]["default"]
            parameters.append(
                click.Option(
                    ["--{}".format(param_name)],
                    default=default,
                    help=
                    "Specify the {} name you'd like, otherwise the default = {}"
                    .format(param_name, default),
                ))

        command_callback = functools.partial(self.cmd_implementation,
                                             self.events_lib,
                                             self.top_level_cmd_name, cmd_name)

        cmd = click.Command(
            name=cmd_name,
            short_help=self.subcmd_definition[cmd_name]["help"],
            params=parameters,
            callback=command_callback,
        )

        cmd = configuration_option(provider=TomlProvider(
            section="parameters"))(debug_option(cmd))
        return cmd