Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings for changing optimist behavior #101

Closed
nanobowers opened this issue Aug 26, 2018 · 2 comments
Closed

Settings for changing optimist behavior #101

nanobowers opened this issue Aug 26, 2018 · 2 comments

Comments

@nanobowers
Copy link
Collaborator

Per longstanding PR #83, I have some ideas on ways to enhance behavior of optimist in ways that may not be backward compatible (see below). In order to make these new behaviors opt-in, it would be nice to have a way to tell optimist how to enable them.

Some implementation ideas include:

  1. inside Optimist::options block, e.g.:
opts = Optimist.options do
  enable_some_setting
  opt :elk, "elk"
end
  1. as arguments to Optimist.options
opts = Optimist.options(some_setting: true) do
  opt :yak, "yak"
end
  1. Via class methods to set a global
Optimist.some_setting = true
opts = Optimist.options do
  opt :moose, "moose"
end

Downsides are:

  • Alternative-1 causes order dependence (of the setting enablement and the opt command) which feels like it's not in the spirit of most DSLs.
  • Alternative-2 causes problems with the cloaker function that is in Optimist.new
  • Alternative-3 is ugly since it applies globally.

Would like maintainer/interested parties from previous PR's opinions ( @kbrock @Fryguy @jrafanie @chrisarcand ) on the best implementation before trying to resurrect #83.

For reference, suggested behavior enhancements would include the following and will probably be in separate PRs going forward:

  • :enable_inexact_match : Allow minimum unambigous number of characters to match a long option (similar to Perl Getopt::Long)
  • :disable_auto_short_opts : Prevent automatic creation of short options
  • :enable_suggestions : Enables suggestions when unknown arguments are given and DidYouMean is installed.
@nanobowers nanobowers changed the title Best way to apply "settings" for changing optimist behavior Settings for changing optimist behavior Jul 4, 2019
@nanobowers
Copy link
Collaborator Author

Went with option 2 above, PR is #108 which adds inexact_match and suggestions feature. Would be reasonably straightforward to do option 1 above.
This question and associated requests for features has been sitting around over two years now in some form (#83 , etc) if feature additions are not of interest to the maintainers (@kbrock , @Fryguy ), please let me know.

@nanobowers
Copy link
Collaborator Author

Feature forking. https://github.com/nanobowers/optimist_xl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant