MCPcopy
hub / github.com/fastapi/typer / add_typer

Method add_typer

typer/main.py:915–1131  ·  view source on GitHub ↗

Add subcommands to the main app using `app.add_typer()`. Subcommands may be defined in separate modules, ensuring clean separation of code by functionality. Read more in the [Typer docs for SubCommands](https://typer.tiangolo.com/tutorial/subcommands/add-typer/).

(
        self,
        typer_instance: "Typer",
        *,
        name: Annotated[
            str | None,
            Doc(
                """
                The name of this subcommand.
                See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's name,
                and which one takes priority.
                """
            ),
        ] = Default(None),
        cls: Annotated[
            type[TyperGroup] | None,
            Doc(
                """
                The class of this subcommand. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
                Otherwise, should be a subtype of `TyperGroup`.
                """
            ),
        ] = Default(None),
        invoke_without_command: Annotated[
            bool,
            Doc(
                """
                By setting this to `True`, you can make sure a callback is executed even when no subcommand is provided.
                """
            ),
        ] = Default(False),
        no_args_is_help: Annotated[
            bool,
            Doc(
                """
                If this is set to `True`, running a command without any arguments will automatically show the help page.
                """
            ),
        ] = Default(False),
        subcommand_metavar: Annotated[
            str | None,
            Doc(
                """
                **Note**: you probably shouldn't use this parameter, it is inherited
                from Click and supported for compatibility.

                ---

                How to represent the subcommand argument in help.
                """
            ),
        ] = Default(None),
        chain: Annotated[
            bool,
            Doc(
                """
                **Note**: you probably shouldn't use this parameter, it is inherited
                from Click and supported for compatibility.

                ---

                Allow passing more than one subcommand argument.
                """
            ),
        ] = Default(False),
        result_callback: Annotated[
            Callable[..., Any] | None,
            Doc(
                """
                **Note**: you probably shouldn't use this parameter, it is inherited
                from Click and supported for compatibility.

                ---

                A function to call after the group's and subcommand's callbacks.
                """
            ),
        ] = Default(None),
        # Command
        context_settings: Annotated[
            dict[Any, Any] | None,
            Doc(
                """
                Pass configurations for the [context](https://typer.tiangolo.com/tutorial/commands/context/).
                Available configurations can be found in the docs for Click's `Context` [here](https://click.palletsprojects.com/en/stable/api/#context).
                """
            ),
        ] = Default(None),
        callback: Annotated[
            Callable[..., Any] | None,
            Doc(
                """
                Add a callback to this app.
                See [the tutorial about callbacks](https://typer.tiangolo.com/tutorial/commands/callback/) for more details.
                """
            ),
        ] = Default(None),
        help: Annotated[
            str | None,
            Doc(
                """
                Help text for the subcommand.
                See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's help,
                and which one takes priority.
                """
            ),
        ] = Default(None),
        epilog: Annotated[
            str | None,
            Doc(
                """
                Text that will be printed right after the help text.
                """
            ),
        ] = Default(None),
        short_help: Annotated[
            str | None,
            Doc(
                """
                A shortened version of the help text that can be used e.g. in the help table listing subcommands.
                When not defined, the normal `help` text will be used instead.
                """
            ),
        ] = Default(None),
        options_metavar: Annotated[
            str | None,
            Doc(
                """
                In the example usage string of the help text for a command, the default placeholder for various arguments is `[OPTIONS]`.
                Set `options_metavar` to change this into a different string. When `None`, the default value will be used.
                """
            ),
        ] = Default(None),
        add_help_option: Annotated[
            bool,
            Doc(
                """
                **Note**: you probably shouldn't use this parameter, it is inherited
                from Click and supported for compatibility.

                ---

                By default each command registers a `--help` option. This can be disabled by this parameter.
                """
            ),
        ] = Default(True),
        hidden: Annotated[
            bool,
            Doc(
                """
                Hide this command from help outputs. `False` by default.
                """
            ),
        ] = Default(False),
        deprecated: Annotated[
            bool,
            Doc(
                """
                Mark this command as deprecated in the help outputs. `False` by default.
                """
            ),
        ] = False,
        # Rich settings
        rich_help_panel: Annotated[
            str | None,
            Doc(
                """
                Set the panel name of the command when the help is printed with Rich.
                """
            ),
        ] = Default(None),
    )

Source from the content-addressed store, hash-verified

913 return decorator
914
915 def add_typer(
916 self,
917 typer_instance: "Typer",
918 *,
919 name: Annotated[
920 str | None,
921 Doc(
922 """
923 The name of this subcommand.
924 See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's name,
925 and which one takes priority.
926 """
927 ),
928 ] = Default(None),
929 cls: Annotated[
930 type[TyperGroup] | None,
931 Doc(
932 """
933 The class of this subcommand. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
934 Otherwise, should be a subtype of `TyperGroup`.
935 """
936 ),
937 ] = Default(None),
938 invoke_without_command: Annotated[
939 bool,
940 Doc(
941 """
942 By setting this to `True`, you can make sure a callback is executed even when no subcommand is provided.
943 """
944 ),
945 ] = Default(False),
946 no_args_is_help: Annotated[
947 bool,
948 Doc(
949 """
950 If this is set to `True`, running a command without any arguments will automatically show the help page.
951 """
952 ),
953 ] = Default(False),
954 subcommand_metavar: Annotated[
955 str | None,
956 Doc(
957 """
958 **Note**: you probably shouldn't use this parameter, it is inherited
959 from Click and supported for compatibility.
960
961 ---
962
963 How to represent the subcommand argument in help.
964 """
965 ),
966 ] = Default(None),
967 chain: Annotated[
968 bool,
969 Doc(
970 """
971 **Note**: you probably shouldn't use this parameter, it is inherited
972 from Click and supported for compatibility.

Calls 3

_info_val_strMethod · 0.95
DefaultFunction · 0.85
TyperInfoClass · 0.85