Giter Site home page Giter Site logo

Comments (7)

alecthomas avatar alecthomas commented on August 16, 2024

Can you expand on what the use case for this is?

from kingpin.

edgard avatar edgard commented on August 16, 2024

One of the most common case for me is loading a config file using a flag: --config=/etc/whatever.json

If I use Dispatch/Action, I have to initialize the config file load from inside each function dispatched.

from kingpin.

alecthomas avatar alecthomas commented on August 16, 2024

Okay. So it seems like you'd be okay with all the values being fully populated before the Dispatch function is called?

If so, that is good news, because that's what will be happening here soon! At the moment value population, dispatch and validation all occur intermingled (as you've found), but this will be split into three distinct passes.

from kingpin.

edgard avatar edgard commented on August 16, 2024

Sure! It does help a lot. I would still need to call my own initialization from inside the functions, but at least that makes it possible to do so!

I think this might impact other use cases as both codegangsta's cli and cobra implements something similar:

https://github.com/codegangsta/cli/blob/master/app.go#L35-L40

https://github.com/spf13/cobra/blob/master/cobra.go#L34-L39

spf13/cobra#53

from kingpin.

alecthomas avatar alecthomas commented on August 16, 2024

For your --config=file flag, a more idiomatic solution would be to make a custom parser. Create one that returns your parsed config structure.

from kingpin.

alecthomas avatar alecthomas commented on August 16, 2024

I think what you want to achieve should be possible in v2-unstable by using the top-level Application.Action(f) callback. This would let you load configuration settings before any other actions are called.

from kingpin.

edgard avatar edgard commented on August 16, 2024

Awesome!! Thank you very much! 👍

from kingpin.

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.