Giter Club home page Giter Club logo

Comments (5)

janluke avatar janluke commented on July 3, 2024

AnySet is a Predicate (something you can put in the condition of If), not a Constraint. You want to use require_any instead.

from cloup.

janluke avatar janluke commented on July 3, 2024

Thanks for this awesome package!

You're welcome :)

from cloup.

janluke avatar janluke commented on July 3, 2024

You can't do require_any("param1", "param2") though. A constraint applied to an option group applies to all options of the group. It's possible to express what you want but not as you did. Check the docs: https://cloup.readthedocs.io/en/stable/pages/constraints.html#applying-constraints

from cloup.

bertsky avatar bertsky commented on July 3, 2024

Oh, my bad. Thanks for explaining!

Yes, so I figure I could use the group's kwarg constraint for the unconditional require_one, and then add another top-level decorator with If just for the two options.

from cloup.

bertsky avatar bertsky commented on July 3, 2024

Fantastic, that worked:

@cloup.option_group(
    'list to be replaced',
    cloup.option('--strings1', cls=OptionEatAll, type=tuple, help='as strings'),
    cloup.option('--files1', cls=OptionEatAll, type=tuple, help='as file paths of strings'),
    cloup.option('--filelist1', type=cloup.File('r'), help='as text file with file paths of strings'),
    constraint=cloup.constraints.require_one)
@cloup.constraint(
    cloup.constraints.If('show_files',
                         then=cloup.constraints.require_one),
    ['files1', 'filelist1'])
nmalign -f --strings1 "${STRINGS1[@]}" --strings2 "${STRINGS2[@]}"
Error: when --show-files is set, exactly 1 of the following parameters must be set:
  --files1
  --filelist1

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.