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

Transform ls's -g/-G option to keyword args #437

Merged
merged 4 commits into from
Nov 10, 2022
Merged

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Nov 10, 2022

Leveraging the transform_args capability in #430, this PR introduces -g / -G option to ls to pass grep option.

irb(main)[01:0]> erb = ERB.new('src')
=>
#<ERB:0x00007f009bf992f8
...
irb(main)[02:0]> ls erb
ERB#methods:
  def_class  def_method   def_module  encoding  filename  filename=  lineno  lineno=  location=  make_compiler  result  result_with_hash
  run        set_eoutvar  src
instance variables: @_init  @encoding  @filename  @frozen_string  @lineno  @src
=> nil
irb(main)[03:0]> ls erb -G result
ERB#methods: result  result_with_hash
=> nil

@k0kubun k0kubun requested a review from st0012 November 10, 2022 07:40
@k0kubun k0kubun force-pushed the ls-grep branch 2 times, most recently from 7b3c275 to d623a0d Compare November 10, 2022 08:06
@st0012
Copy link
Member

st0012 commented Nov 10, 2022

Looks like a very useful feature 👍

A few questions:

  • Why is --grep's short version -G? I feel -g fits convention better (like -v for --version) and is easier to type.
    • I know -G comes from Pry, so I have the same question for it too 😅
  • Can we limit the supported cases to just 2 or even 1? I'll reduce the maintenance effort and make introducing new flags easier.
    • Specifically, I'd expect flags and args have fixed positions.
    • <cmd> <flag> <arg> matches my general command line experience better.
    • In debug, commands don't have flags but have options, like break Foo#bar if: <condition>. Do we want to lean toward debug more or make it closer to Pry 🤔

@k0kubun
Copy link
Member Author

k0kubun commented Nov 10, 2022

Why is --grep's short version -G? I feel -g fits convention better (like -v for --version) and is easier to type.
I know -G comes from Pry, so I have the same question for

Because Pry also has --globals/-g. I think it's not a bad idea to reserve -g for that instead of taking the risk to end up with the other way in IRB while I still don't intend to work on --globals/-g support in this PR.

matches my general command line experience better.

The workflow is usually,

  1. Input $ ls erb. See too many methods.
  2. C-p to resurrect ls erb. Start typing -G result, which naturally makes it ls erb -G result.

So for this use case, I think <cmd> <arg> <flag> is a better experience. I'm okay to only leave that support, but once I come up with a use case that needs the other case after using that version, I would just come here again and file a patch to support that.

Do you want to support only <cmd> <arg> <flag> first?

@k0kubun k0kubun force-pushed the ls-grep branch 2 times, most recently from d4cdea2 to c1f3012 Compare November 10, 2022 17:54
@st0012
Copy link
Member

st0012 commented Nov 10, 2022

I think -g is more like another command than an option of the ls command. Like it can't even be used with an object

[7] pry(main)> ls Object -g
Error: -g does not make sense with a specified Object

I'm incline to not supporting ls --globals and has something like globals for that feature instead. With that in mind, I don't want to reserve -g for it, which makes more sense for --grep IMO.

Do you want to support only first?

Yeah your example is very convincing. That's go with that format first 👍

@k0kubun
Copy link
Member Author

k0kubun commented Nov 10, 2022

With that in mind, I don't want to reserve -g for it, which makes more sense for --grep IMO.

What about accepting both -g and -G then? With the amount of times I've used ls -G, it feels nearly impossible for my fingers to just forget typing -G on ls. If we support only -g, I'd be so stressed out that I'll just monkey-patch this again. I will likely not be a user of -g myself until the world uninstalls Pry everywhere. Given that we pretend to be Pry-compatible in some ways, I think it's a useful feature to be somewhat compatible with Pry.

@st0012
Copy link
Member

st0012 commented Nov 10, 2022

Yeah that makes sense.
I also wonder if people actually type --grep instead of just -G. Perhaps we can add -g, -G for now, and --grep when requested?

@k0kubun
Copy link
Member Author

k0kubun commented Nov 10, 2022

I also wonder if people actually type --grep instead of just -G. Perhaps we can add -g, -G for now, and --grep when requested?

works for me 👍 9e53571

I think this PR is ready for your review again.

Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

👍
There seems to be a flaky test failed in a truffleruby suite.

@k0kubun k0kubun merged commit b7556a2 into ruby:master Nov 10, 2022
@k0kubun k0kubun deleted the ls-grep branch November 10, 2022 22:55
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 10, 2022
(ruby/irb#437)

* Transform ls's --grep/-G option to keyword args

* Make --grep less flexible

* Support -g instead of --grep

* Suppress warnings from symbol aliases
@k0kubun k0kubun changed the title Transform ls's --grep/-G option to keyword args Transform ls's -g/-G option to keyword args Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants