Skip to content

Need feature to share options or arguments between commands #405

Open
@allinhtml

Description

@allinhtml

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from typing import Optional, List

import typer
import os

app = typer.Typer()

@app.command()
def start(
  debug: bool = typer.Option(False),
  output_dir: str = typer.Option(os.getcwd()),
  flows: Optional[List[str]] = typer.Option(None, "--flow", "-f")):
  typer.echo(f"Debug mode: {debug}")
  typer.echo(f"Output Dir: {output_dir}")
  typer.echo(f"start flows: {flows}")


@app.command()
def stop(
  debug: bool = typer.Option(False),
  output_dir: str = typer.Option(os.getcwd())):
  typer.echo(f"Debug mode: {debug}")
  typer.echo(f"Output Dir: {output_dir}")
  typer.echo("STOP!")

@app.command()
def clean(
  debug: bool = typer.Option(False),
  output_dir: str = typer.Option(os.getcwd())):
  typer.echo(f"Debug mode: {debug}")
  typer.echo(f"Output Dir: {output_dir}")
  typer.echo("STOP!")


if __name__ == "__main__":
    app()

Description

How can we easily add common options into multiple commands like debug or output_directory?

Related question - #153 - But this is not working as expected. Help section don't show message properly as commented here.

Operating System

Linux, Windows, macOS

Operating System Details

No response

Typer Version

ALL

Python Version

ALL

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion or problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions