Coder Social home page Coder Social logo

Comments (1)

edornd avatar edornd commented on June 29, 2024

Hey @gusutabopb, thank you for the good suggestion, in fact this was one of the major missing features.
Your proposal is quite neat, the only issue I have with it is that the existence of a cli kwarg is of course not explicitly stated since it's not native to pydantic, as well as the use of a dictionary it' not very "declarative", meaning that it's hard to know what to provide as input (thinking about IDE suggestions like IntelliSense).
At the same time this modification has a very low impact, which is nice.

A solution I was instead considering consisted in creating a custom CLIField inheriting Field, to provide this functionality this way (which requires a bit more work than yours, but probably not that much):

class Config(BaseModel):
    name: str = CLIField("-n", "--old-name", default="Mark", description="Your name", other_custom_cli_stuff="value")
    count: int = CLIField("-c")

Basically it would prioritize the functionality the CLI needs without interfering with pydantic. The main logic of CLIField would remain in the init, handling its custom fields and forwarding to super for the rest, in the right order.
Let me know what you think about this.

And thanks to you for giving this thing a try!

from clidantic.

Related Issues (14)

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.