Delete the `gist` command
This command was moved to the [pry-jist][1] plugin. Pry allows good extensibility and this command doesn't feel like something that should be in Pry Core. I suspect not many people use it, let alone know about it. The concept of optional dependencies also feels awkward (the `gist` gem). It's a strong indication that the command should be moved outside Pry Core (or we should just depend on `gist`). [1]: https://github.com/pry/pry-jist
This commit is contained in:
parent
e23aabdbfc
commit
7c091f2fcb
|
@ -177,7 +177,6 @@ Style/DoubleNegation:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/pry/code.rb'
|
- 'lib/pry/code.rb'
|
||||||
- 'lib/pry/command_set.rb'
|
- 'lib/pry/command_set.rb'
|
||||||
- 'lib/pry/commands/gist.rb'
|
|
||||||
- 'lib/pry/commands/whereami.rb'
|
- 'lib/pry/commands/whereami.rb'
|
||||||
- 'lib/pry/method.rb'
|
- 'lib/pry/method.rb'
|
||||||
- 'lib/pry/method/weird_method_locator.rb'
|
- 'lib/pry/method/weird_method_locator.rb'
|
||||||
|
|
1
Gemfile
1
Gemfile
|
@ -2,7 +2,6 @@ source 'https://rubygems.org'
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
gem 'rake', '~> 10.0'
|
gem 'rake', '~> 10.0'
|
||||||
gem 'gist'
|
|
||||||
gem 'yard'
|
gem 'yard'
|
||||||
gem 'rspec', '~> 3.8.0'
|
gem 'rspec', '~> 3.8.0'
|
||||||
gem 'simplecov', '~> 0.16', require: false
|
gem 'simplecov', '~> 0.16', require: false
|
||||||
|
|
|
@ -109,7 +109,6 @@ require 'pry/commands/gem_open'
|
||||||
require 'pry/commands/gem_readme'
|
require 'pry/commands/gem_readme'
|
||||||
require 'pry/commands/gem_search'
|
require 'pry/commands/gem_search'
|
||||||
require 'pry/commands/gem_stats'
|
require 'pry/commands/gem_stats'
|
||||||
require 'pry/commands/gist'
|
|
||||||
require 'pry/commands/help'
|
require 'pry/commands/help'
|
||||||
require 'pry/commands/hist'
|
require 'pry/commands/hist'
|
||||||
require 'pry/commands/import_set'
|
require 'pry/commands/import_set'
|
||||||
|
|
|
@ -101,10 +101,10 @@ class Pry
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def pry_output_content
|
def pry_output_content
|
||||||
pry_array_content_as_string(
|
pry_array_content_as_string(
|
||||||
_pry_.output_ring, self.class.output_result_ranges
|
_pry_.output_ring,
|
||||||
) do |v|
|
self.class.output_result_ranges,
|
||||||
_pry_.config.gist.inspecter.call(v)
|
&:pretty_inspect
|
||||||
end
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The selected `_pry_.input_ring` as a string, as specified by
|
# The selected `_pry_.input_ring` as a string, as specified by
|
||||||
|
|
|
@ -1,103 +0,0 @@
|
||||||
class Pry
|
|
||||||
class Command
|
|
||||||
class Gist < Pry::ClassCommand
|
|
||||||
match 'gist'
|
|
||||||
group 'Misc'
|
|
||||||
description 'Upload code, docs, history to https://gist.github.com/.'
|
|
||||||
command_options requires_gem: "gist"
|
|
||||||
|
|
||||||
banner <<-'BANNER'
|
|
||||||
Usage: gist [OPTIONS] [--help]
|
|
||||||
|
|
||||||
The gist command enables you to gist code from files and methods to github.
|
|
||||||
|
|
||||||
gist -i 20 --lines 1..3
|
|
||||||
gist Pry#repl --lines 1..-1
|
|
||||||
gist Rakefile --lines 5
|
|
||||||
BANNER
|
|
||||||
|
|
||||||
def setup
|
|
||||||
require 'gist'
|
|
||||||
end
|
|
||||||
|
|
||||||
def options(opt)
|
|
||||||
CodeCollector.inject_options(opt)
|
|
||||||
opt.on :login, "Authenticate the gist gem with GitHub"
|
|
||||||
opt.on :p, :public, "Create a public gist (default: false)", default: false
|
|
||||||
opt.on :clip, "Copy the selected content to clipboard instead, do NOT " \
|
|
||||||
"gist it", default: false
|
|
||||||
end
|
|
||||||
|
|
||||||
def process
|
|
||||||
return ::Gist.login! if opts.present?(:login)
|
|
||||||
|
|
||||||
cc = CodeCollector.new(args, opts, _pry_)
|
|
||||||
|
|
||||||
raise CommandError, "Found no code to gist." if cc.content =~ /\A\s*\z/
|
|
||||||
|
|
||||||
if opts.present?(:clip)
|
|
||||||
clipboard_content(cc.content)
|
|
||||||
else
|
|
||||||
# we're overriding the default behavior of the 'in' option (as
|
|
||||||
# defined on CodeCollector) with our local behaviour.
|
|
||||||
content = opts.present?(:in) ? input_content : cc.content
|
|
||||||
gist_content content, cc.file
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def clipboard_content(content)
|
|
||||||
::Gist.copy(content)
|
|
||||||
output.puts "Copied content to clipboard!"
|
|
||||||
end
|
|
||||||
|
|
||||||
def input_content
|
|
||||||
content = ""
|
|
||||||
CodeCollector.input_expression_ranges.each do |range|
|
|
||||||
input_expressions = _pry_.input_ring[range] || []
|
|
||||||
Array(input_expressions).each_with_index do |code, index|
|
|
||||||
corrected_index = index + range.first
|
|
||||||
next unless code && code != ""
|
|
||||||
|
|
||||||
content << code
|
|
||||||
next unless code !~ /;\Z/
|
|
||||||
|
|
||||||
content << comment_expression_result_for_gist(
|
|
||||||
_pry_.config.gist.inspecter.call(_pry_.output_ring[corrected_index])
|
|
||||||
).to_s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
content
|
|
||||||
end
|
|
||||||
|
|
||||||
def comment_expression_result_for_gist(result)
|
|
||||||
content = ""
|
|
||||||
result.lines.each_with_index do |line, index|
|
|
||||||
content << index == 0 ? "# => #{line}" : "# #{line}"
|
|
||||||
end
|
|
||||||
|
|
||||||
content
|
|
||||||
end
|
|
||||||
|
|
||||||
def gist_content(content, filename)
|
|
||||||
response = ::Gist.gist(
|
|
||||||
content, filename: filename || "pry_gist.rb", public: !!opts[:p]
|
|
||||||
)
|
|
||||||
if response
|
|
||||||
url = response['html_url']
|
|
||||||
message = "Gist created at URL #{url}"
|
|
||||||
begin
|
|
||||||
::Gist.copy(url)
|
|
||||||
message << ", which is now in the clipboard."
|
|
||||||
rescue ::Gist::ClipboardError # rubocop:disable Lint/HandleExceptions
|
|
||||||
end
|
|
||||||
|
|
||||||
output.puts message
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Pry::Commands.add_command(Pry::Command::Gist)
|
|
||||||
Pry::Commands.alias_command 'clipit', 'gist --clip'
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -119,7 +119,6 @@ class Pry
|
||||||
file_completions: proc { Dir["."] },
|
file_completions: proc { Dir["."] },
|
||||||
ls: Pry::Config.from_hash(Pry::Command::Ls::DEFAULT_OPTIONS),
|
ls: Pry::Config.from_hash(Pry::Command::Ls::DEFAULT_OPTIONS),
|
||||||
completer: Pry::InputCompleter,
|
completer: Pry::InputCompleter,
|
||||||
gist: Pry::Config.from_hash(inspecter: proc(&:pretty_inspect)),
|
|
||||||
history: Pry::Config.from_hash(
|
history: Pry::Config.from_hash(
|
||||||
should_save: true, should_load: true
|
should_save: true, should_load: true
|
||||||
).tap do |history|
|
).tap do |history|
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
# These tests are out of date.
|
|
||||||
# They need to be updated for the new 'gist' API, but im too sleepy to
|
|
||||||
# do that now.
|
|
||||||
describe 'gist' do
|
|
||||||
it 'has a dependency on the jist gem' do
|
|
||||||
expect(Pry::Command::Gist.command_options[:requires_gem]).to eq("gist")
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
|
||||||
Pad.gist_calls = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
# In absence of normal mocking, just monkeysmash these with no undoing after.
|
|
||||||
module ::Gist # rubocop:disable Style/ClassAndModuleChildren
|
|
||||||
class << self
|
|
||||||
def login!
|
|
||||||
Pad.gist_calls[:login!] = true
|
|
||||||
end
|
|
||||||
|
|
||||||
def gist(*args)
|
|
||||||
Pad.gist_calls[:gist_args] = args
|
|
||||||
{ 'html_url' => 'http://gist.blahblah' }
|
|
||||||
end
|
|
||||||
|
|
||||||
def copy(content)
|
|
||||||
Pad.gist_calls[:copy_args] = content
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'nominally logs in' do
|
|
||||||
pry_eval 'gist --login'
|
|
||||||
expect(Pad.gist_calls[:login!]).not_to be_nil
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue