Giter Site home page Giter Site logo

Comments (6)

euri10 avatar euri10 commented on August 10, 2024 1

thanks

from typer.

randallpittman avatar randallpittman commented on August 10, 2024 1

Hi, Is there a way to have a --version-type eager option with required Arguments? That is, the arguments are required unless you're just calling --version.

from typer.

JnyJny avatar JnyJny commented on August 10, 2024

I got your code fragment to work if I declared version like this:

import typer

app = typer.Typer()

def print_version(ctx, param, value):
    if not value:
        return
    typer.echo("Version MM.mm.pp")
    raise typer.Exit()

@app.command()
def main(version: bool = typer.Option(False, "--version", "-v", is_eager=True, callback=print_version):
    print("foobar")

To be honest, I was hoping that Typer() would pass through the click.version_option(VERSION) decorator. This works but feels awkward.

from typer.

euri10 avatar euri10 commented on August 10, 2024

To be honest, I was hoping that Typer() would pass through the click.version_option(VERSION) decorator. This works but feels awkward.

yep that's the 1st thing I tried but so far didn't manage it
this solution works indeed but you need to type app main --version while on click app --version would make it,
there might be a way !

from typer.

tiangolo avatar tiangolo commented on August 10, 2024

Thanks for the discussion @euri10 and @JnyJny !

I just added docs about --version with is_eager: https://typer.tiangolo.com/tutorial/options/version/

from typer.

tiangolo avatar tiangolo commented on August 10, 2024

@randallpittman probably better to ask in a new issue following the template. 🤓

Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I'm checking each one in order.

from typer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.