From 2205f62ec672643b845579f8687b0372b256f485 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 28 Feb 2018 11:36:23 +0000 Subject: irb: add pry support. Make `brew irb` optionally support `pry`. While doing so, also make it a `dev-cmd`. --- Library/Homebrew/cmd/irb.rb | 40 ------------------------ Library/Homebrew/dev-cmd/irb.rb | 54 +++++++++++++++++++++++++++++++++ Library/Homebrew/extend/ARGV.rb | 4 +++ Library/Homebrew/manpages/brew.1.md.erb | 9 ++++-- 4 files changed, 64 insertions(+), 43 deletions(-) delete mode 100644 Library/Homebrew/cmd/irb.rb create mode 100644 Library/Homebrew/dev-cmd/irb.rb (limited to 'Library') diff --git a/Library/Homebrew/cmd/irb.rb b/Library/Homebrew/cmd/irb.rb deleted file mode 100644 index 4cd3d4c9e..000000000 --- a/Library/Homebrew/cmd/irb.rb +++ /dev/null @@ -1,40 +0,0 @@ -#: * `irb` [`--examples`]: -#: Enter the interactive Homebrew Ruby shell. -#: -#: If `--examples` is passed, several examples will be shown. - -require "formula" -require "keg" -require "irb" - -class Symbol - def f(*args) - Formulary.factory(to_s, *args) - end -end - -class String - def f(*args) - Formulary.factory(self, *args) - end -end - -module Homebrew - module_function - - def irb - $LOAD_PATH.unshift("#{HOMEBREW_LIBRARY_PATH}/cask/lib") - require "hbc" - - if ARGV.include? "--examples" - puts "'v8'.f # => instance of the v8 formula" - puts ":hub.f.installed?" - puts ":lua.f.methods - 1.methods" - puts ":mpd.f.recursive_dependencies.reject(&:installed?)" - else - ohai "Interactive Homebrew Shell" - puts "Example commands available with: brew irb --examples" - IRB.start - end - end -end diff --git a/Library/Homebrew/dev-cmd/irb.rb b/Library/Homebrew/dev-cmd/irb.rb new file mode 100644 index 000000000..700cbe009 --- /dev/null +++ b/Library/Homebrew/dev-cmd/irb.rb @@ -0,0 +1,54 @@ +#: * `irb` [`--examples`] [`--pry`]: +#: Enter the interactive Homebrew Ruby shell. +#: +#: If `--examples` is passed, several examples will be shown. +#: If `--pry` is passed or HOMEBREW_PRY is set, pry will be +#: used instead of irb. + +class Symbol + def f(*args) + Formulary.factory(to_s, *args) + end +end + +class String + def f(*args) + Formulary.factory(self, *args) + end +end + +module Homebrew + module_function + + def irb + if ARGV.include? "--examples" + puts "'v8'.f # => instance of the v8 formula" + puts ":hub.f.installed?" + puts ":lua.f.methods - 1.methods" + puts ":mpd.f.recursive_dependencies.reject(&:installed?)" + return + end + + if ARGV.pry? + Homebrew.install_gem_setup_path! "pry" + require "pry" + Pry.config.prompt_name = "brew" + else + require "irb" + end + + require "formula" + require "keg" + + $LOAD_PATH.unshift("#{HOMEBREW_LIBRARY_PATH}/cask/lib") + require "hbc" + + ohai "Interactive Homebrew Shell" + puts "Example commands available with: brew irb --examples" + if ARGV.pry? + Pry.start + else + IRB.start + end + end +end diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index d9da014f0..2bc84620a 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -267,6 +267,10 @@ module HomebrewArgvExtension include? "--fetch-HEAD" end + def pry? + include?("--pry") || !ENV["HOMEBREW_PRY"].nil? + end + # eg. `foo -ns -i --bar` has three switches, n, s and i def switch?(char) return false if char.length > 1 diff --git a/Library/Homebrew/manpages/brew.1.md.erb b/Library/Homebrew/manpages/brew.1.md.erb index 533e1d594..618e050f6 100644 --- a/Library/Homebrew/manpages/brew.1.md.erb +++ b/Library/Homebrew/manpages/brew.1.md.erb @@ -183,6 +183,10 @@ can take several different forms: *Note:* Homebrew doesn't require permissions for any of the scopes. + * `HOMEBREW_INSTALL_BADGE`: + Text printed before the installation summary of each successful build. + Defaults to the beer emoji. + * `HOMEBREW_LOGS`: If set, Homebrew will use the given directory to store log files. @@ -220,9 +224,8 @@ can take several different forms: If set, Homebrew will not use the GitHub API for e.g searches or fetching relevant issues on a failed install. - * `HOMEBREW_INSTALL_BADGE`: - Text printed before the installation summary of each successful build. - Defaults to the beer emoji. + * `HOMEBREW_PRY`: + If set, Homebrew will use `pry` for the `brew irb` command. * `HOMEBREW_SVN`: When exporting from Subversion, Homebrew will use `HOMEBREW_SVN` if set, -- cgit v1.2.3