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

Add initconfig support for command defaults, allow strings as config keys #257

Open
wants to merge 3 commits into
base: gli-2
Choose a base branch
from

Conversation

hyperbolist
Copy link

Fixes #63

The initconfig command will now write out all of the switches and flags for any commands and any subcommands. It writes config keys as strings, though symbols will still work.

@@ -0,0 +1,17 @@
# adapted from https://gist.github.com/Integralist/9503099
class Object
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not monkeypatch core classes? This is likely going to break anyone that uses GLI with Rails/ActiveSupport.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking over the rest of the PR, I think a better way to do this is make a class whose job is to load the configuration and have it do all this string/symbol copying, so we don't infect every object in the entire system with a method that's only needed in a couple of places.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fair. It hadn't occurred to me that a GLI project might also have ActiveSupport loaded.

@davetron5000
Copy link
Owner

Thanks for doing this! Other than the issues with monkeypatching, the overall change looks great!

@hyperbolist
Copy link
Author

Got rid of the monkeypatching, which I admit was reckless.


# adapted from https://gist.github.com/Integralist/9503099
def self.apply_indifferent_access_to(obj)
return obj.reduce({}) do |memo, (k, v)|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to nitpick, but can you use a more traditional if construct? Trailing ifs for multiple lines is really confusing to me.

@davetron5000
Copy link
Owner

Thanks and sorry for the delay in looking at this. Just one tiny nitpick, but otherwise this looks good. Thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants