-
Notifications
You must be signed in to change notification settings - Fork 74
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
Able to access options set by global_option() outside of the command block #7
Comments
From @akostadinov on February 16, 2015 18:17 I am thinking that a separate |
@pruan-rht Can you put together a code sample for how you would want to use the global option? I'm not sure why you need to access the option outside of the command block. @akostadinov your suggestion seems to address a different issue; and I'm not really sure what use case that helps with. Again, a code sample of intended usage would be great for discussion. |
Also, I had some suggestions for a similar problem on this issue: tj/commander#81 Please take a look and let me know if that addresses your use case or not. |
From @pruan-rht on February 16, 2015 22:56 @ggilder, thanks for getting back so fast. Unfortunately, your suggestioin on #81 does not address the issue. |
Sorry to hear that. If you can provide a code sample to show what you'd like to have, I'm sure we can figure something out. |
From @pruan-rht on February 16, 2015 23:27 @ggilder, below is an example. Without being able to access the global_option outside of the sub commands, I would need to add the line 'update_plan_id(options) if options.plan_id' to each of the supported commands. I deally, I want to have that line executed globally once, so I don't need to add that line for all of the sub-commands. Hope that clarifies the issue at hand. thanks in advance def run
|
Thanks, I think this and @akostadinov 's comments on #81 have clarified the use case. In your case, though, could you just use the existing facility to provide a block for a global option? I'm wondering if something like this would work: def run
# ...
global_option('-p', '--plan_id PLAN_ID_OR_NAME', 'specify the plan name or plan id') do |plan_id|
update_plan_id(plan_id)
end
# commands etc.
end That wouldn't work, however, if |
From @pruan-rht on February 17, 2015 0:59 @ggilder, you are correct, that will work for my particular case fortunately since the update_plan method doesn't need other global_options. Thank you for the pointer...I think this would be a good example to put into the README/example section to cut down the noise to you. Anyway, I still think it would be good to have a way to access the global_options for the other use case. |
From @pruan-rht on February 16, 2015 18:0
Sometime, it's useful to be able to access options that at set in the global_option() be accessible outside of the command block so that I can do initialization of codes that are global to all sub commands. For example
global_option('-p', '--plan_id PLAN_ID_OR_NAME', 'specify the plan name or plan id')
command :rename do |c|
...
c.action do |arg, options|
...
I want to check the option plan_id outside of the c.action block for the various commands that this global_option applies to
Copied from original issue: tj/commander#94
The text was updated successfully, but these errors were encountered: