@@ -524,9 +524,7 @@ def _print_subcommands(self, data, nested_content, markdown_help=False, settings
524524
525525 definitions = map_nested_definitions (nested_content )
526526 items = []
527- full_subcommand_name_true = (
528- ('full_subcommand_name' , True ) in self .config .sphinx_argparse_conf .items ()
529- )
527+ full_subcommand_name_true = self .config .sphinxarg_full_subcommand_name
530528 domain = cast (ArgParseDomain , self .env .domains [ArgParseDomain .name ])
531529
532530 if 'children' in data :
@@ -859,6 +857,7 @@ def generate(
859857
860858
861859class CommandsByGroupIndex (Index ):
860+ # Defaults (can be overridden through `conf.py`):
862861 name = 'by-group'
863862 localname = 'Commands by Group'
864863
@@ -977,28 +976,27 @@ def _create_temporary_dummy_file(
977976
978977
979978def configure_ext (app : Sphinx ) -> None :
980- conf = app .config .sphinx_argparse_conf
981979 domain = cast (ArgParseDomain , app .env .domains [ArgParseDomain .name ])
982980 build_index = False
983981 build_by_group_index = False
984- if 'commands_by_group_index_file_suffix' in conf :
985- build_by_group_index = True
986- CommandsByGroupIndex .name = conf .get ('commands_by_group_index_file_suffix' )
987- if 'commands_by_group_index_title' in conf :
988- build_by_group_index = True
989- CommandsByGroupIndex .localname = conf .get ('commands_by_group_index_title' )
990- if ('commands_index_in_toctree' , True ) in conf .items ():
982+
983+ CommandsByGroupIndex .name = app .config .sphinxarg_commands_by_group_index_file_suffix
984+ CommandsByGroupIndex .localname = app .config .sphinxarg_commands_by_group_index_title
985+
986+ if app .config .sphinxarg_commands_index_in_toctree :
991987 build_index = True
992988 docname = f'{ ArgParseDomain .name } -{ CommandsIndex .name } .rst'
993989 _create_temporary_dummy_file (app , domain , docname , CommandsIndex .localname )
994- if ('commands_by_group_index_in_toctree' , True ) in conf .items ():
990+
991+ if app .config .sphinxarg_commands_by_group_index_in_toctree :
995992 build_by_group_index = True
996993 docname = f'{ ArgParseDomain .name } -{ CommandsByGroupIndex .name } .rst'
997994 _create_temporary_dummy_file (app , domain , docname , CommandsByGroupIndex .localname )
998995
999- if build_index or ( 'build_commands_index' , True ) in conf . items () :
996+ if build_index or app . config . sphinxarg_build_commands_index :
1000997 domain .indices .append (CommandsIndex )
1001- if build_by_group_index or ('build_commands_by_group_index' , True ) in conf .items ():
998+
999+ if build_by_group_index or app .config .sphinxarg_build_commands_by_group_index :
10021000 domain .indices .append (CommandsByGroupIndex )
10031001
10041002 # Call setup so that :ref:`commands-...` are link targets.
@@ -1009,7 +1007,18 @@ def setup(app: Sphinx):
10091007 app .setup_extension ('sphinx.ext.autodoc' )
10101008 app .add_domain (ArgParseDomain )
10111009 app .add_directive ('argparse' , ArgParseDirective )
1012- app .add_config_value ('sphinx_argparse_conf' , {}, 'html' , types = {dict })
1010+
1011+ # Config options must be mentioned in ``usage.rst`` too!
1012+
1013+ app .add_config_value ('sphinxarg_full_subcommand_name' , False , 'html' , bool )
1014+ app .add_config_value ('sphinxarg_build_commands_index' , False , 'html' , bool )
1015+ app .add_config_value ('sphinxarg_commands_index_in_toctree' , False , 'html' , bool )
1016+
1017+ app .add_config_value ('sphinxarg_build_commands_by_group_index' , False , 'html' , bool )
1018+ app .add_config_value ('sphinxarg_commands_by_group_index_in_toctree' , False , 'html' , bool )
1019+ app .add_config_value ('sphinxarg_commands_by_group_index_file_suffix' , CommandsByGroupIndex .name , 'html' , str )
1020+ app .add_config_value ('sphinxarg_commands_by_group_index_title' , CommandsByGroupIndex .localname , 'html' , str )
1021+
10131022 app .connect ('builder-inited' , configure_ext )
10141023 app .connect ('build-finished' , _delete_temporary_files )
10151024 return {
0 commit comments