JEG2 / highline

A higher level command-line oriented interface.
Other
1.29k stars 137 forks source link

Separate auto-completion from answer type #66

Closed davispuh closed 11 years ago

davispuh commented 11 years ago

I think it's quite bad design to mix answer conversion and auto-completion using same variable answer_type. So this is a little separation giving more control to app, ie. allowing to enable auto-competition without requiring that answer will be enforced to exact value from array.

eg. (user is still allowed to input 'yellow', but can use completion for green)

ask("color?") { |h|
            h.validate = nil
            h.readline = true
            h.completion=["red","green","blue"]
        }

if completion isn't specified it will be same as answer_type thus consistent with that it used to be.

this also kinda fixes #65, but probably it can be improved with more functionality.

JEG2 commented 11 years ago

I need to think about this one.

If nothing else, it's an interface change that would require a version bump.

I worry a little about the interplay between these two options, though I haven't yet come up with a specific example of my concerns…

davispuh commented 11 years ago

I don't see any issues with this and I think it's correct way with separation, I'm not really sure what other way could be...

JEG2 commented 11 years ago

Well, I'm considering a total HighLine redesign. One thought is to handle Question modifiers as Decorators that get added on much like Rack's middleware. I believe this would drastically simplify testing HighLine, which is surely needed.

This is just one idea that I have.

davispuh commented 11 years ago

idea is good, but while it's not implemented there's no other choice so this patch is for current design, of course I would love seeing next version, but as we know it will take time and I assume that you've other things to do same as me...

JEG2 commented 11 years ago

Your change requires a version bump. It's not backwards compatible, since people will have to stop using one option and start using another.

If we have to do that anyway, I would rather get my long desired cleanup out of it. Does that make sense?

davispuh commented 11 years ago

go for it ;)

FYI these changes are backward compatible, when completion isn't specified it will be same as answer_type, so setting answer_type will still work same as it's for previous versions. lib/highline/question.rb#L36

If this isn't backwards compatible then why does all tests pass? and I didn't changed any.

JEG2 commented 11 years ago

I did not notice that. You are right. I apologize.