Giter Site home page Giter Site logo

Comments (5)

janluke avatar janluke commented on June 12, 2024 1

Thanks for the detailed report. I'll check if I can do something about this as soon as I can. Meanwhile, I want to suggest you an alternative, which is in my opinion more flexible and future-proof. My suggestion is to move the group arguments, especially if required, to the subcommands. This if more flexible since if tomorrow you want to add a command that doesn't require those credentials, you will be able to do it.

import cloup
from cloup.constraints import require_one


class Common:
    credentials = cloup.option_group(
        "credentials",
        cloup.option("--foo", help="foo"),
        cloup.option("--bar", help="bar"),
        constraint=require_one,
    )


@cloup.group()
def cli():
    """Top level group text."""
    pass


@cli.command()
@Common.credentials
def subcommand(foo, bar):
    """Subcommand help text."""


if __name__ == "__main__":
    cli()

from cloup.

janluke avatar janluke commented on June 12, 2024 1

Btw, Click has the same problem with required Group parameters:

import click

@click.group()
@click.option("--foo", help="foo", required=True)
def cli(foo):
    """Top level group text."""

@cli.command()
def subcommand():
    """Subcommand help text."""

if __name__ == "__main__":
    cli("subcommand --help".split())

I think required parameters at the Group level should probably be avoided.

from cloup.

janluke avatar janluke commented on June 12, 2024 1

No, the Cloup part is solvable and I'm going to push the fix.

from cloup.

ryancausey avatar ryancausey commented on June 12, 2024

That's a smart idea. I didn't think about giving the decorator a name and re-using it. Thanks!

from cloup.

ryancausey avatar ryancausey commented on June 12, 2024

So if this is a Click issue then, should this be closed?

from cloup.

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.