molybdenum-99 / reality

Comprehensive data proxy to knowledge about real world
MIT License
817 stars 43 forks source link

Interest in a CLI #42

Closed codenamev closed 8 years ago

codenamev commented 8 years ago

Is there any interest in a CLI for this? I made a quick script to expose the describe method, but if anyone else would find this useful I wouldn't mind contributing it.

This is an awesome gem by the way :smile:

zverok commented 8 years ago

What do you mean under CLI?.. If command-line interface, there is bin/reality included (and described in README)

codenamev commented 8 years ago

I do mean command-line interface, and I don't see any reference to command-line usage in the README. Also, the existing bin/reality is pretty unusable as a command line tool since it just opens up an IRB console and doesn't actually expose any of the data directly to IO.

What I'd like to do is expose the results to the command-line so that I can do something like really describe 'reality' in the command line and it would proxy Entity('reality').describe.

zverok commented 8 years ago

Oh, ok, understood now! This thing should be useful, I'd like to see pull-request with it.

Console binary is (briefly) mentioned here: https://github.com/molybdenum-99/reality#uhm-ok-how-to-use-it and in several other places, but it has another goals.

techscientist commented 8 years ago

Nice idea

DannyBen commented 8 years ago

Is there a way to access list elements with really?

$ bin/really "return of the jedi" producers [1]
Error: [#<Reality::Entity?(Rick McCallum)>, #<Reality::Entity?(Howard Kazanjian)>] doesn't respond to [1]
codenamev commented 8 years ago

The command line arguments for the really command are treated as a method chain, with the exception that you can't provide arguments that are methods that take arguments themselves (as is your example with []). So instead, this string of arguments should give you what you expect: bin/really "return of the jedi" producers first

DannyBen commented 8 years ago

I am aware of that. But since the response is often a list, I think there should be support for obtaining list elements naturally, other than the first. Unless a better way comes to mind, I would love to see special handling of [n] arguments, or even better (more natural) to simply allow numbers without square brackets - really "return of the jedi" producers 2 awards 1

Something along the lines of if subcommand is a number and object respond to [] then...

Edit: Something like this branch

And then you do: bin/really "wikipedia" founders 1 occupations 1

Its quick and dirty, just to get boots on the ground.

codenamev commented 8 years ago

My thinking with round one here was to expose the raw output as much as possible. You can achieve fetching of specific nth result by piping the output to the sed command. Something like ... | sed -n 1p will give you the first match. You can even use sed to grab ranges.

I think it may make sense to introduce more "filters" when interacting with lists, but I think for now it'd be better to gauge community use and see what features are demanded once it's been out in the wild ;-)

zverok commented 8 years ago

I agree with @codenamev on it. Next release of reality is scheduled to April 9, and the really command will be promoted in release notes, and then we'll see what people say. (Though @DannyBen's implementation is pretty witty and minimalistic, I should say.)

DannyBen commented 8 years ago

Fair enough. Also.... while the window of opportunity is still open, I would like to raise the issue of naming.

Although I love really for the command line, I would consider reducing the bin count to one.

Advantages:

  1. The reality gem has a reality bin, a common pattern in other gems that expose a binary.
  2. It is a more polite behavior since you "pollute" the global space with one binary, instead of two.

So, an alternative to having reality + really can be:

reality --console - to run console reality QUERIES - to run the CLI

zverok commented 8 years ago

Hmm, yes, I've thinked on this already, but haven't come to any concrete solution. The --console vs QUERIES thing looks quite reasonable, though. WDYT, @codenamev?

codenamev commented 8 years ago

@zverok I agree with @DannyBen that there should be a single command. I think it would make more sense to default to the "console" version as that seems to be a best practice amongst gems. The current command is more of an "interactive Reality shell" than it is a CLI.

If you agree, maybe something like reality --interactive and/or reality -i? Just thinking of how git handles it for rebasing. I can whip this up in another PR pretty quickly if you guys like it.

zverok commented 8 years ago

If you agree, maybe something like reality --interactive and/or reality -i? Just thinking of how git handles it for rebasing. I can whip this up in another PR pretty quickly if you guys like it.

Totally fine for me!

codenamev commented 8 years ago

Closed with 42c7acf116fc3e990368ce0df67d0c042c21be1b (which is now in master).