Giter VIP home page Giter VIP logo

go-options's People

Contributors

gaal avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

elasticdog

go-options's Issues

Callback parser should not need to stop parsing by calling os.Exit

Hello,

when you use a callback parser, there is no other way of stopping parsing the command line arguments than to call os.Exit(). This is inconvenient if you need to do some clean up when you detect that parsing the command line arguments was not successful.

I would like to suggest modifying the signature of the callback parser so that it returns for instance a bool to tell go-options that the parsing process can continue or not.

In the return value of spec.Parse() we would need a way to know if the parsing ended successfully or not. For instance:

spec := options.NewOptions(mySpec).SetParseCallback(MyParseCallback)
opt := spec.Parse(os.Args[1:])
if ! opt.ParsingWasOK() {
// Do some cleanup here
}

In the current situation, we have to call the cleanup process in every 'case' of the 'switch' of the parse callback. If your command accepts several options, this may be a lot of code to repeat.

Best regards,

Flags consumed as values of previous flags

Hello,

I have been exploring your package for building a command line tool and I find it very useful, so thanks for sharing it.

However, I found a behavior that can be misleading for the future users of my tool. For illustrating it I'm using your example 2.

If you don't provide the value for the option '--output-encoding' which does require a value and provide instead another valid option, such as '--verbose', the '--verbose' string is interpreted as the value of '--output-encoding'. This is a user error for not providing a value and it would be nice to be able to show an appropriate message. See for instance:

$ testGoOptions --output-encoding --verbose
I will concatenate the files: []
Input charset: utf-8
Output charset: --verbose <<<<< '-verbose' is taken as the value of option '--output-encoding'
Chance for a cookie: 0.10

I'm having the same issue with my tool. In the callback function that I provide, I have no easy means to validate that the third argument (i.e. the value of the option) is actually another option, because this information is stored in the OptionSpec type which is opaque.

Would you consider adding a method for OptionSpec that allows callbacks to determine if a given string ('--verbose' in this example) is actually an option? By using this method, my callback would be able to check the option value and display the appropriate message.

Do you see a better way to solve this issue?

Thanks in advance for considering this modification.

Extra options should include those in the format param=value

The regex which matches option formats slices off the =value for non-option arguments. Sometimes an app wants to have its own internal interpretation of arguments which includes the equals sign.

Expected:
./myprogram --option=value param1=value1 param2=value2
should produce 2 Extra options, namely "param1=value1" and "param2=value2"

Actual:
The result doesn't make sense. I see "value2", "=" in Extra.

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.