@@ -940,3 +940,78 @@ def world():
940940 ).lstrip (),
941941 '\n ' .join (output ),
942942 )
943+
944+
945+ class AutoEnvvarPrefixTestCase (unittest .TestCase ):
946+ """Validate ``click auto_envvar_prefix``-setup instances."""
947+
948+ def test_basics (self ):
949+ """Validate a click application with ``auto_envvar_prefix`` option enabled."""
950+
951+ @click .command (
952+ context_settings = {"auto_envvar_prefix" : "PREFIX" },
953+ )
954+ @click .option ('--param' , help = 'Help for param' )
955+ @click .option ('--other-param' , help = 'Help for other-param' )
956+ @click .option (
957+ '--param-with-explicit-envvar' ,
958+ help = 'Help for param-with-explicit-envvar' ,
959+ envvar = "EXPLICIT_ENVVAR" ,
960+ )
961+ def cli_with_auto_envvars ():
962+ """A simple CLI with auto-env vars ."""
963+
964+ cli = cli_with_auto_envvars
965+ ctx = click .Context (cli , info_name = 'cli' , auto_envvar_prefix = "PREFIX" )
966+ output = list (ext ._format_command (ctx , nested = 'full' ))
967+
968+ self .assertEqual (
969+ textwrap .dedent (
970+ """
971+ A simple CLI with auto-env vars .
972+
973+ .. program:: cli
974+ .. code-block:: shell
975+
976+ cli [OPTIONS]
977+
978+ .. rubric:: Options
979+
980+ .. option:: --param <param>
981+
982+ Help for param
983+
984+ .. option:: --other-param <other_param>
985+
986+ Help for other-param
987+
988+ .. option:: --param-with-explicit-envvar <param_with_explicit_envvar>
989+
990+ Help for param-with-explicit-envvar
991+
992+ .. rubric:: Environment variables
993+
994+ .. _cli-param-PREFIX_PARAM:
995+
996+ .. envvar:: PREFIX_PARAM
997+ :noindex:
998+
999+ Provide a default for :option:`--param`
1000+
1001+ .. _cli-other_param-PREFIX_OTHER_PARAM:
1002+
1003+ .. envvar:: PREFIX_OTHER_PARAM
1004+ :noindex:
1005+
1006+ Provide a default for :option:`--other-param`
1007+
1008+ .. _cli-param_with_explicit_envvar-EXPLICIT_ENVVAR:
1009+
1010+ .. envvar:: EXPLICIT_ENVVAR
1011+ :noindex:
1012+
1013+ Provide a default for :option:`--param-with-explicit-envvar`
1014+ """
1015+ ).lstrip (),
1016+ '\n ' .join (output ),
1017+ )
0 commit comments