mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
DRY gist command's docs vs tests
This commit is contained in:
parent
27bbc4383a
commit
c51f75a9fc
2 changed files with 49 additions and 25 deletions
|
@ -26,27 +26,51 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Gist
|
||||||
|
DESCRIPTION = 'Upload code, docs, history to https://gist.github.com/'
|
||||||
|
INVOCATIONS = {
|
||||||
|
:method => ['gist -m my_method', 'gist the method my_method' ],
|
||||||
|
:doc => ['gist -d my_method', 'gist the docs for my_method' ],
|
||||||
|
:input => ['gist -i 1..2', 'gist the input expressions from 1 to 2' ],
|
||||||
|
:kommand => ['gist -k show-method', 'gists pry command show-method' ],
|
||||||
|
:class => ['gist -c Pry', 'gist the Pry class' ],
|
||||||
|
:jist => ['jist -c Pry', 'alias for the above' ],
|
||||||
|
:lines => ['gist -m my_method --lines 2..-2', 'limit by range' ],
|
||||||
|
:cliponly => ['gist -m my_method --clip', 'copy (but do not gist)' ],
|
||||||
|
:clipit => ['clipit -m my_method', 'alias for the above' ],
|
||||||
|
# TODO:
|
||||||
|
# :var =>
|
||||||
|
# :hist =>
|
||||||
|
# :file =>
|
||||||
|
}
|
||||||
|
class << self
|
||||||
|
def example_code sym; INVOCATIONS[sym][0] end
|
||||||
|
def example_description sym; INVOCATIONS[sym][1] end
|
||||||
|
def examples_docs
|
||||||
|
INVOCATIONS.keys.map do |e|
|
||||||
|
"e.g.: %-33s # %s " % [example_code(e), example_description(e)]
|
||||||
|
end.join "\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
Pry::Commands.create_command "gist" do
|
Pry::Commands.create_command "gist" do
|
||||||
include Pry::Helpers::DocumentationHelpers
|
include Pry::Helpers::DocumentationHelpers
|
||||||
|
|
||||||
group 'Misc'
|
group 'Misc'
|
||||||
description "Gist a method or expression history to GitHub."
|
description Pry::Gist::DESCRIPTION
|
||||||
command_options :requires_gem => 'jist', :shellwords => false
|
command_options :requires_gem => 'jist', :shellwords => false
|
||||||
|
|
||||||
banner <<-USAGE
|
banner <<-USAGE
|
||||||
Usage: gist [OPTIONS] [METH]
|
Usage: gist [options]
|
||||||
Gist method (doc or source) or input expression to GitHub.
|
#{Pry::Gist::DESCRIPTION}
|
||||||
|
|
||||||
If you'd like to permanently associate your gists with your GitHub account run `gist --login`.
|
If you'd like to associate your gists with your GitHub account, run:
|
||||||
|
gist --login
|
||||||
|
|
||||||
e.g: gist -m my_method # gist the method my_method
|
|
||||||
e.g: gist -d my_method # gist the documentation for my_method
|
|
||||||
e.g: gist -i 1..10 # gist the input expressions from 1 to 10
|
|
||||||
e.g: gist -k show-method # gist the command show-method
|
|
||||||
e.g: gist -c Pry # gist the Pry class
|
|
||||||
e.g: gist -m my_method --lines 2..-2 # gist from lines 2 to the second-last of the hello_world method
|
|
||||||
e.g: gist -m my_method --clip # Copy my_method source to clipboard, do not gist it.
|
|
||||||
USAGE
|
USAGE
|
||||||
|
banner << Pry::Gist.examples_docs << "\n"
|
||||||
|
|
||||||
attr_accessor :content, :filename
|
attr_accessor :content, :filename
|
||||||
|
|
||||||
|
|
|
@ -32,22 +32,14 @@ describe 'gist' do
|
||||||
end
|
end
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
INVOCATIONS = {
|
RANDOM_COUPLE_OF_LINES = %w(a=1 b=2)
|
||||||
:method => ['gist -m my_method' ],
|
run_case = proc do |sym|
|
||||||
:doc => ['gist -d my_method' ],
|
actual_command = Pry::Gist.example_code(sym)
|
||||||
:input => ['a = 1', 'b = 2', 'gist -i 1..2' ],
|
pry_eval EXAMPLE_REPL_METHOD, RANDOM_COUPLE_OF_LINES, actual_command
|
||||||
:kommand => ['gist -k show-method' ],
|
end
|
||||||
:class => ['gist -c Pry' ],
|
|
||||||
:jist => ['jist -c Pry'],
|
|
||||||
:lines => ['gist -m my_method --lines 2..-2' ],
|
|
||||||
:cliponly => ['gist -m my_method --clip' ],
|
|
||||||
:clipit => ['clipit -m my_method' ],
|
|
||||||
}
|
|
||||||
|
|
||||||
run_case = proc {|sym| pry_eval *([EXAMPLE_REPL_METHOD] + INVOCATIONS[sym]) }
|
|
||||||
|
|
||||||
it 'deduces filenames' do
|
it 'deduces filenames' do
|
||||||
INVOCATIONS.keys.each do |e|
|
Pry::Gist::INVOCATIONS.keys.each do |e|
|
||||||
run_case.call(e)
|
run_case.call(e)
|
||||||
if $jist_gisted
|
if $jist_gisted
|
||||||
text, args = $jist_gisted
|
text, args = $jist_gisted
|
||||||
|
@ -62,4 +54,12 @@ describe 'gist' do
|
||||||
run_case.call(:clipit).should == run_case.call(:cliponly)
|
run_case.call(:clipit).should == run_case.call(:cliponly)
|
||||||
run_case.call(:jist).should == run_case.call(:class)
|
run_case.call(:jist).should == run_case.call(:class)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has a reasonable --help' do
|
||||||
|
help = pry_eval('gist --help')
|
||||||
|
Pry::Gist::INVOCATIONS.keys.each do |e|
|
||||||
|
help.should.include? Pry::Gist.example_code(e)
|
||||||
|
help.should.include? Pry::Gist.example_description(e)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue