rails-sh 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
+ gem "rake", "0.8.7"
9
10
  gem "rspec", "~> 2.3.0"
10
11
  gem "bundler", "~> 1.0.0"
11
12
  gem "jeweler", "~> 1.5.2"
@@ -24,5 +24,6 @@ PLATFORMS
24
24
  DEPENDENCIES
25
25
  bundler (~> 1.0.0)
26
26
  jeweler (~> 1.5.2)
27
+ rake (= 0.8.7)
27
28
  rcov
28
29
  rspec (~> 2.3.0)
@@ -23,7 +23,7 @@ Execute rake task:
23
23
 
24
24
  Generate a controller:
25
25
 
26
- rails> g controller foo bar
26
+ rails> rails generate controller foo bar
27
27
  $ rails g controller foo bar
28
28
  create app/controllers/foo_controller.rb
29
29
  route get "foo/bar"
@@ -45,6 +45,17 @@ Run console:
45
45
 
46
46
  please type help
47
47
 
48
+ == Configuration
49
+
50
+ rails-sh will try to load '~/railsshrc' as configuration.
51
+
52
+ Example:
53
+
54
+ # ~/railsshrc
55
+ Rails::Sh::Command.define 'my_command' do |arg|
56
+ puts "Execute my_command with arg(`#{arg}`)!"
57
+ end
58
+
48
59
  == TODO
49
60
 
50
61
  == Contributing to rails-sh
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.5.0
@@ -1,4 +1,5 @@
1
1
  require 'readline'
2
+ require 'rails/sh/helpers'
2
3
  require 'rails/sh/forkable'
3
4
  require 'rails/sh/rails'
4
5
  require 'rails/sh/rake'
@@ -14,11 +15,13 @@ module Rails
14
15
 
15
16
  require 'rails/sh/commands'
16
17
 
17
- puts "Rails.env: #{::Rails.env}"
18
- puts "type `help` to print help"
18
+ begin; load "~/.railsshrc"; rescue LoadError; end
19
+
20
+ puts "\e[36mRails.env: #{::Rails.env}\e[0m"
21
+ puts "\e[36mtype `help` to print help\e[0m"
19
22
 
20
23
  setup_readline
21
- while buf = Readline.readline("rails> ", true)
24
+ while buf = Readline.readline(prompt, true)
22
25
  line = buf.strip
23
26
  next if line.empty?
24
27
  begin
@@ -32,6 +35,10 @@ module Rails
32
35
  end
33
36
  end
34
37
 
38
+ def prompt
39
+ "%s> " % "rails-sh(#{::Rails.root.basename})"
40
+ end
41
+
35
42
  def setup_readline
36
43
  Readline.basic_word_break_characters = ""
37
44
  Readline.completion_proc = Command.completion_proc
@@ -30,13 +30,27 @@ module Rails
30
30
  end
31
31
 
32
32
  def completion_proc
33
- lambda { |line| completions.grep(/#{Regexp.quote(line)}/) }
33
+ lambda { |line|
34
+ regex = /#{Regexp.quote(line)}/
35
+ completions.map { |completion|
36
+ case completion
37
+ when String
38
+ completion if completion.match(regex)
39
+ when Proc
40
+ completion.call(line)
41
+ end
42
+ }.compact
43
+ }
34
44
  end
35
45
 
36
46
  def completions
37
47
  @completions ||= []
38
48
  end
39
49
 
50
+ def completions=(completions)
51
+ @completions = completions
52
+ end
53
+
40
54
  def clear
41
55
  commands.clear
42
56
  completions.clear
@@ -42,7 +42,7 @@ Command.define 'bundle' do |arg|
42
42
  Rails::Sh::Bundler.invoke(arg)
43
43
  end
44
44
 
45
- Rails::Sh::Bundler.sub_commands.map do |c|
45
+ (Rails::Sh::Bundler.sub_commands - ['init']).map do |c|
46
46
  Command.completions << "bundle #{c}"
47
47
  end
48
48
 
@@ -63,6 +63,12 @@ Command.define 'reload' do
63
63
  Rails::Sh::Rails.reload!
64
64
  end
65
65
 
66
+ Command.define 'log' do |arg|
67
+ puts "\e[7mCtrl-C to quit\e[0m"
68
+ system 'tail', '-f', Rails.root.join('log', (arg || 'development') + '.log').to_s
69
+ end
70
+ Command.completions += %w(development test production).map { |i| "log #{i}" }
71
+
66
72
  Command.define 'exit' do
67
73
  exit
68
74
  end
@@ -1,11 +1,23 @@
1
+ require 'stringio'
2
+
1
3
  module Rails
2
4
  module Sh
3
5
  module Forkable
6
+ include Rails::Sh::Helpers
7
+
4
8
  def invoke(line)
5
9
  run_before_fork
6
10
  pid = fork do
7
11
  run_after_fork
8
- _invoke(line)
12
+
13
+ begin
14
+ $stdout = StringIO.new
15
+ _invoke(line)
16
+ ensure
17
+ output = $stdout.string
18
+ lesspipe output
19
+ $stdout = STDOUT
20
+ end
9
21
  end
10
22
  Process.waitpid(pid)
11
23
  end
@@ -0,0 +1,60 @@
1
+ module Rails
2
+ module Sh
3
+ module Helpers
4
+ # copy from pry: https://github.com/pry/pry
5
+ #
6
+ # Create scrollable output via less!
7
+ #
8
+ # This command runs `less` in a subprocess, and gives you the IO to its STDIN pipe
9
+ # so that you can communicate with it.
10
+ #
11
+ # Example:
12
+ #
13
+ # lesspipe do |less|
14
+ # 50.times { less.puts "Hi mom!" }
15
+ # end
16
+ #
17
+ # The default less parameters are:
18
+ # * Allow colour
19
+ # * Don't wrap lines longer than the screen
20
+ # * Quit immediately (without paging) if there's less than one screen of text.
21
+ #
22
+ # You can change these options by passing a hash to `lesspipe`, like so:
23
+ #
24
+ # lesspipe(:wrap=>false) { |less| less.puts essay.to_s }
25
+ #
26
+ # It accepts the following boolean options:
27
+ # :color => Allow ANSI colour codes?
28
+ # :wrap => Wrap long lines?
29
+ # :always => Always page, even if there's less than one page of text?
30
+ #
31
+ def lesspipe(*args)
32
+ if args.any? and args.last.is_a?(Hash)
33
+ options = args.pop
34
+ else
35
+ options = {}
36
+ end
37
+
38
+ output = args.first if args.any?
39
+
40
+ params = []
41
+ params << "-R" unless options[:color] == false
42
+ params << "-S" unless options[:wrap] == true
43
+ params << "-F" unless options[:always] == true
44
+ if options[:tail] == true
45
+ params << "+\\>"
46
+ $stderr.puts "Seeking to end of stream..."
47
+ end
48
+ params << "-X"
49
+
50
+ IO.popen("less #{params * ' '}", "w") do |less|
51
+ if output
52
+ less.puts output
53
+ else
54
+ yield less
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -4,15 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{rails-sh}
8
- s.version = "1.4.0"
7
+ s.name = "rails-sh"
8
+ s.version = "1.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jugyo"]
12
- s.date = %q{2011-02-03}
13
- s.default_executable = %q{rails-sh}
14
- s.description = %q{The Rails Shell to execute sub commands of rails quickly.}
15
- s.email = %q{jugyo.org@gmail.com}
12
+ s.date = "2011-11-23"
13
+ s.description = "The Rails Shell to execute sub commands of rails quickly."
14
+ s.email = "jugyo.org@gmail.com"
16
15
  s.executables = ["rails-sh"]
17
16
  s.extra_rdoc_files = [
18
17
  "LICENSE.txt",
@@ -33,6 +32,7 @@ Gem::Specification.new do |s|
33
32
  "lib/rails/sh/command.rb",
34
33
  "lib/rails/sh/commands.rb",
35
34
  "lib/rails/sh/forkable.rb",
35
+ "lib/rails/sh/helpers.rb",
36
36
  "lib/rails/sh/rails.rb",
37
37
  "lib/rails/sh/rake.rb",
38
38
  "rails-sh.gemspec",
@@ -40,11 +40,11 @@ Gem::Specification.new do |s|
40
40
  "spec/rails/sh_spec.rb",
41
41
  "spec/spec_helper.rb"
42
42
  ]
43
- s.homepage = %q{http://github.com/jugyo/rails-sh}
43
+ s.homepage = "http://github.com/jugyo/rails-sh"
44
44
  s.licenses = ["MIT"]
45
45
  s.require_paths = ["lib"]
46
- s.rubygems_version = %q{1.5.0}
47
- s.summary = %q{The Rails Shell}
46
+ s.rubygems_version = "1.8.11"
47
+ s.summary = "The Rails Shell"
48
48
  s.test_files = [
49
49
  "spec/rails/sh/command_spec.rb",
50
50
  "spec/rails/sh_spec.rb",
@@ -55,17 +55,20 @@ Gem::Specification.new do |s|
55
55
  s.specification_version = 3
56
56
 
57
57
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
+ s.add_development_dependency(%q<rake>, ["= 0.8.7"])
58
59
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
59
60
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
60
61
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
61
62
  s.add_development_dependency(%q<rcov>, [">= 0"])
62
63
  else
64
+ s.add_dependency(%q<rake>, ["= 0.8.7"])
63
65
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
64
66
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
67
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
66
68
  s.add_dependency(%q<rcov>, [">= 0"])
67
69
  end
68
70
  else
71
+ s.add_dependency(%q<rake>, ["= 0.8.7"])
69
72
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
70
73
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
71
74
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
@@ -58,5 +58,16 @@ describe Rails::Sh::Command do
58
58
  Rails::Sh::Command.completion_proc.call('foo').should =~ ['foo']
59
59
  Rails::Sh::Command.completion_proc.call('rake').should =~ ['rake routes', 'rake spec']
60
60
  end
61
+
62
+ context 'with blocks for completion' do
63
+ before do
64
+ Rails::Sh::Command.completions.clear
65
+ Rails::Sh::Command.completions << lambda { |line| 'block' }
66
+ end
67
+
68
+ it 'return completions' do
69
+ Rails::Sh::Command.completion_proc.call('foo').should =~ ['block']
70
+ end
71
+ end
61
72
  end
62
73
  end
metadata CHANGED
@@ -1,72 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rails-sh
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.0
4
5
  prerelease:
5
- version: 1.4.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - jugyo
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-02-03 00:00:00 +09:00
14
- default_executable: rails-sh
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &2177367420 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.7
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2177367420
25
+ - !ruby/object:Gem::Dependency
17
26
  name: rspec
18
- requirement: &id001 !ruby/object:Gem::Requirement
27
+ requirement: &2177366860 !ruby/object:Gem::Requirement
19
28
  none: false
20
- requirements:
29
+ requirements:
21
30
  - - ~>
22
- - !ruby/object:Gem::Version
31
+ - !ruby/object:Gem::Version
23
32
  version: 2.3.0
24
33
  type: :development
25
34
  prerelease: false
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *2177366860
36
+ - !ruby/object:Gem::Dependency
28
37
  name: bundler
29
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirement: &2177366240 !ruby/object:Gem::Requirement
30
39
  none: false
31
- requirements:
40
+ requirements:
32
41
  - - ~>
33
- - !ruby/object:Gem::Version
42
+ - !ruby/object:Gem::Version
34
43
  version: 1.0.0
35
44
  type: :development
36
45
  prerelease: false
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *2177366240
47
+ - !ruby/object:Gem::Dependency
39
48
  name: jeweler
40
- requirement: &id003 !ruby/object:Gem::Requirement
49
+ requirement: &2177365660 !ruby/object:Gem::Requirement
41
50
  none: false
42
- requirements:
51
+ requirements:
43
52
  - - ~>
44
- - !ruby/object:Gem::Version
53
+ - !ruby/object:Gem::Version
45
54
  version: 1.5.2
46
55
  type: :development
47
56
  prerelease: false
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
57
+ version_requirements: *2177365660
58
+ - !ruby/object:Gem::Dependency
50
59
  name: rcov
51
- requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirement: &2177365100 !ruby/object:Gem::Requirement
52
61
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
57
66
  type: :development
58
67
  prerelease: false
59
- version_requirements: *id004
68
+ version_requirements: *2177365100
60
69
  description: The Rails Shell to execute sub commands of rails quickly.
61
70
  email: jugyo.org@gmail.com
62
- executables:
71
+ executables:
63
72
  - rails-sh
64
73
  extensions: []
65
-
66
- extra_rdoc_files:
74
+ extra_rdoc_files:
67
75
  - LICENSE.txt
68
76
  - README.rdoc
69
- files:
77
+ files:
70
78
  - .document
71
79
  - .rspec
72
80
  - Gemfile
@@ -81,44 +89,42 @@ files:
81
89
  - lib/rails/sh/command.rb
82
90
  - lib/rails/sh/commands.rb
83
91
  - lib/rails/sh/forkable.rb
92
+ - lib/rails/sh/helpers.rb
84
93
  - lib/rails/sh/rails.rb
85
94
  - lib/rails/sh/rake.rb
86
95
  - rails-sh.gemspec
87
96
  - spec/rails/sh/command_spec.rb
88
97
  - spec/rails/sh_spec.rb
89
98
  - spec/spec_helper.rb
90
- has_rdoc: true
91
99
  homepage: http://github.com/jugyo/rails-sh
92
- licenses:
100
+ licenses:
93
101
  - MIT
94
102
  post_install_message:
95
103
  rdoc_options: []
96
-
97
- require_paths:
104
+ require_paths:
98
105
  - lib
99
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
100
107
  none: false
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- hash: -857922454327872908
105
- segments:
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ segments:
106
113
  - 0
107
- version: "0"
108
- required_rubygems_version: !ruby/object:Gem::Requirement
114
+ hash: 3117646239956155231
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
116
  none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- version: "0"
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
114
121
  requirements: []
115
-
116
122
  rubyforge_project:
117
- rubygems_version: 1.5.0
123
+ rubygems_version: 1.8.11
118
124
  signing_key:
119
125
  specification_version: 3
120
126
  summary: The Rails Shell
121
- test_files:
127
+ test_files:
122
128
  - spec/rails/sh/command_spec.rb
123
129
  - spec/rails/sh_spec.rb
124
130
  - spec/spec_helper.rb