ro_commands 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +54 -0
- data/bin/ro +32 -0
- data/bin/ro_client +6 -0
- data/bin/ro_server +8 -0
- data/config/rorc.rb +2 -0
- data/lib/bash_builder.rb +92 -0
- data/lib/bash_builder_helper.rb +34 -0
- data/lib/bash_debug.rb +55 -0
- data/lib/bash_templates/git.sh +10 -0
- data/lib/bash_templates/gitflow.sh +0 -0
- data/lib/bash_templates/misc.sh +66 -0
- data/lib/bash_templates/rails.sh +0 -0
- data/lib/bash_templates/rubymine_idea.sh +5 -0
- data/lib/bash_templates/shortcuts.sh +1 -0
- data/lib/builder_templates/completions.erb +18 -0
- data/lib/builder_templates/git_flow.erb +3 -0
- data/lib/builder_templates/rails.erb +3 -0
- data/lib/builder_templates/set_envs.erb +9 -0
- data/lib/drb/client.rb +22 -0
- data/lib/drb/server.rb +33 -0
- data/lib/git_flow_builder_helper.rb +34 -0
- data/lib/methods.rb +19 -0
- data/lib/rails_builder_helper.rb +41 -0
- data/lib/ro_commands.rb +34 -0
- data/lib/ro_commands/base.rb +95 -0
- data/lib/ro_commands/core_ext/hash.rb +5 -0
- data/lib/ro_commands/core_ext/string.rb +14 -0
- data/lib/ro_commands/core_ext/symbol.rb +0 -0
- data/lib/ro_commands/core_ext/thor.rb +71 -0
- data/lib/ro_commands/dsl/file.rb +25 -0
- data/lib/ro_commands/file_actions.rb +128 -0
- data/lib/ro_commands/generate.rb +32 -0
- data/lib/ro_commands/generators/base_generator.rb +68 -0
- data/lib/ro_commands/generators/ex.rb +56 -0
- data/lib/ro_commands/generators/lib.rb +25 -0
- data/lib/ro_commands/generators/spec_file.rb +74 -0
- data/lib/ro_commands/generators/templates/ex.erb +30 -0
- data/lib/ro_commands/generators/templates/spec.erb +2 -0
- data/lib/ro_commands/git.rb +89 -0
- data/lib/ro_commands/git_flow.rb +111 -0
- data/lib/ro_commands/helpers/all.rb +8 -0
- data/lib/ro_commands/helpers/all_files.rb +21 -0
- data/lib/ro_commands/helpers/bash.rb +33 -0
- data/lib/ro_commands/helpers/out.rb +29 -0
- data/lib/ro_commands/hook.rb +102 -0
- data/lib/ro_commands/info.rb +55 -0
- data/lib/ro_commands/misc.rb +77 -0
- data/lib/ro_commands/navigate.rb +56 -0
- data/lib/ro_commands/processes.rb +12 -0
- data/lib/ro_commands/rails.rb +210 -0
- data/lib/ro_commands/refactor.rb +78 -0
- data/lib/ro_commands/ro_helper.rb +76 -0
- data/lib/ro_commands/ro_procs.rb +106 -0
- data/lib/ro_commands/rubymine.rb +17 -0
- data/lib/ro_commands/shortcuts.rb +67 -0
- data/lib/ro_commands/try.rb +11 -0
- data/lib/ro_commands/version.rb +3 -0
- data/lib/ro_commands/zeus.rb +18 -0
- data/lib/ro_commands/zeus_templates/custom_plan.rb +18 -0
- data/lib/ro_commands/zeus_templates/zeus.json +24 -0
- data/lib/ro_helper.rb +25 -0
- data/lib/shortcuts.rb +43 -0
- data/lib/spec_element.rb +24 -0
- data/lib/spec_element/describe.rb.erb +9 -0
- data/lib/tasks/roro_commands_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/roro_commands_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +235 -0
data/lib/drb/client.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "drb"
|
2
|
+
require "ro_commands/helpers/all_files"
|
3
|
+
require "ro_commands/helpers/out"
|
4
|
+
require "ro_commands/core_ext/string"
|
5
|
+
|
6
|
+
item = ARGV.shift
|
7
|
+
meth = ARGV.shift
|
8
|
+
args = ARGV
|
9
|
+
|
10
|
+
DRb.start_service
|
11
|
+
file = RoCommands.file_map.keys.grep(%r{#{item}}).first
|
12
|
+
|
13
|
+
if file
|
14
|
+
port = RoCommands.file_map[file.to_sym]
|
15
|
+
|
16
|
+
#Out.out "starting #{File.basename(file.to_s).gsub(%r{\.rb}, "")}"
|
17
|
+
drb_obj = DRbObject.new_with_uri("druby://localhost:#{port}")
|
18
|
+
r = drb_obj.start(["drb_#{meth}", *args])
|
19
|
+
#Out.out "r:#{r} file:#{File.basename __FILE__} line:#{__LINE__}"
|
20
|
+
Out.out(r)
|
21
|
+
end
|
22
|
+
|
data/lib/drb/server.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "drb"
|
2
|
+
require "ro_commands"
|
3
|
+
require "ro_commands/core_ext/thor"
|
4
|
+
require "ro_commands/core_ext/string"
|
5
|
+
require "ro_commands/helpers/all"
|
6
|
+
require "ro_commands/helpers/out"
|
7
|
+
require "drb"
|
8
|
+
|
9
|
+
Out.out "starting service"
|
10
|
+
DRb::DRbServer.make_config(verbose: true)
|
11
|
+
#Out.out "RoCommands.file_map:#{RoCommands.file_map} file:#{File.basename __FILE__} line:#{__LINE__}"
|
12
|
+
RoCommands.file_map.each do |file, port|
|
13
|
+
basename = File.basename(file.to_s).gsub(%r{\.rb}, "")
|
14
|
+
klass_name = basename.to_s.camelize
|
15
|
+
|
16
|
+
Out.out "#{RoCommands.const_get(klass_name.to_sym)} defining methods"
|
17
|
+
RoCommands.const_get(klass_name.to_sym).class_eval do
|
18
|
+
RoCommands.const_get(klass_name.to_sym).meths.each do |m|
|
19
|
+
desc usage("drb_#{m}"), ""
|
20
|
+
define_method("drb_#{m}".to_sym) do |*args|
|
21
|
+
Out.reset
|
22
|
+
send(m.to_sym, *args)
|
23
|
+
Out.out "Out.msgs:#{Out.msgs} file:#{File.basename __FILE__} line:#{__LINE__}"
|
24
|
+
handle_drb_out
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
url = "druby://localhost:#{port}"
|
30
|
+
puts "#{RoCommands.const_get(klass_name.to_sym)} at #{url}"
|
31
|
+
DRb.start_service(url, RoCommands.const_get(klass_name.to_sym))
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative "ro_helper"
|
2
|
+
module GitFlowBuilderHelper
|
3
|
+
class << self
|
4
|
+
def included(base)
|
5
|
+
base.extend(ClsMeths)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClsMeths
|
10
|
+
|
11
|
+
include ::RoHelper
|
12
|
+
|
13
|
+
class GitFlow < Cmd
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def git_flows
|
18
|
+
cmd 'gfi', "git init && git flow init -f"
|
19
|
+
|
20
|
+
#git flow release
|
21
|
+
cmd 'fr', "git flow release"
|
22
|
+
cmd 'frf', "fr finish", "zeus git_flow get_releases"
|
23
|
+
cmd 'frp', "fr publish", "zeus git_flow get_releases"
|
24
|
+
|
25
|
+
#git flow feature
|
26
|
+
cmd 'ff', "git flow feature"
|
27
|
+
cmd 'frs', "git flow release start"
|
28
|
+
cmd 'ffs', "git flow feature start"
|
29
|
+
cmd 'fff', "ff finish", "zeus git_flow get_features"
|
30
|
+
cmd 'ffc', 'ff checkout', "zeus git flow get_features"
|
31
|
+
cmds
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/methods.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class Methods
|
2
|
+
class << self
|
3
|
+
# get version like ubuntu version
|
4
|
+
# eg 13.10
|
5
|
+
def get_version
|
6
|
+
m = Time.now.to_s.match /(\d+)-(\d+)-(\d+)/
|
7
|
+
year, month, day = m[1], m[2], m[3]
|
8
|
+
year.gsub! '20', ''
|
9
|
+
"#{year}#{month}#{day}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def change_current_version
|
13
|
+
Find.find(Dir.pwd).each do |path|
|
14
|
+
path.match Regexp "/version.rb"
|
15
|
+
File.read
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative "ro_helper"
|
2
|
+
module RailsBuilderHelper
|
3
|
+
class << self
|
4
|
+
def included(base)
|
5
|
+
base.extend(ClsMeths)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClsMeths
|
10
|
+
|
11
|
+
include ::RoHelper
|
12
|
+
|
13
|
+
def rails_cmds
|
14
|
+
cmd 'z', 'zeus'
|
15
|
+
cmd 'zr', 'z rails'
|
16
|
+
cmd 'g', 'z g'
|
17
|
+
cmd 'd', 'z d'
|
18
|
+
|
19
|
+
# generate
|
20
|
+
cmd 'a', 'z g assets'
|
21
|
+
cmd 'c', 'zr controller'
|
22
|
+
cmd 'm', 'zr migration'
|
23
|
+
cmd 'mo', 'zr model'
|
24
|
+
cmd 's', 'zr scaffold'
|
25
|
+
|
26
|
+
|
27
|
+
# destroy
|
28
|
+
cmd 'da', 'd assets', 'zeus rails get_assets'
|
29
|
+
cmd 'dco', 'd controller', 'zeus rails get_controllers'
|
30
|
+
cmd 'dmo', 'd model', 'zeus rails get_models'
|
31
|
+
cmd 'dm', 'd migration', 'zeus rails get_migrations'
|
32
|
+
cmd 'ds', 'd scaffold', 'zeus rails get_scaffold'
|
33
|
+
|
34
|
+
# misc
|
35
|
+
cmd 'mi', 'z rake db:migrate'
|
36
|
+
|
37
|
+
cmd 'bx', "bundle exec"
|
38
|
+
cmds
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/ro_commands.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'find'
|
2
|
+
|
3
|
+
require File.expand_path('../methods', __FILE__)
|
4
|
+
$LOAD_PATH.unshift File.expand_path("../..", __FILE__)
|
5
|
+
require "config/rorc"
|
6
|
+
|
7
|
+
require 'erb'
|
8
|
+
require 'thor'
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
$LOAD_PATH.unshift File.expand_path("../..", __FILE__)
|
12
|
+
$root = File.expand_path("../..", __FILE__)
|
13
|
+
$LOAD_PATH.unshift File.join($root, 'lib')
|
14
|
+
|
15
|
+
require 'ro_commands/base'
|
16
|
+
|
17
|
+
module RoCommands
|
18
|
+
def self.autoload_files_in(dir)
|
19
|
+
Dir[File.join File.expand_path("../#{dir}", __FILE__), "**"].each do |file|
|
20
|
+
if file[/\.rb$/]
|
21
|
+
module_name = File.basename(file).gsub(/\.rb/, '').camelize
|
22
|
+
autoload module_name.to_sym, file
|
23
|
+
autoload module_name.upcase, file
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
autoload :Element, "spec_elelment"
|
29
|
+
|
30
|
+
autoload_files_in "ro_commands/env"
|
31
|
+
|
32
|
+
autoload_files_in 'ro_commands'
|
33
|
+
autoload :Generator, 'ro_commands/generate'
|
34
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'find'
|
3
|
+
|
4
|
+
require "ro_commands/core_ext/string"
|
5
|
+
require "ro_commands/core_ext/hash"
|
6
|
+
require "ro_commands/helpers/out"
|
7
|
+
require "ro_commands/helpers/bash"
|
8
|
+
|
9
|
+
#Thor.class_eval do
|
10
|
+
#
|
11
|
+
# def self.desc(usage, description, options={})
|
12
|
+
# if options[:for]
|
13
|
+
# command = find_and_refresh_command(options[:for])
|
14
|
+
# command.usage = usage if usage
|
15
|
+
# command.description = description if description
|
16
|
+
# else
|
17
|
+
# @usage, @desc, @hide = "#{$ro_commands_argument} #{usage}", description, options[:hide] || false
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#end
|
21
|
+
|
22
|
+
module RoCommands
|
23
|
+
class Base < Thor
|
24
|
+
protected
|
25
|
+
class << self
|
26
|
+
|
27
|
+
def method_added(method)
|
28
|
+
super
|
29
|
+
unless method.match(%r{drb_})
|
30
|
+
meths << method
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def meths
|
35
|
+
@meths.flatten! if @meths.respond_to?(:flatten!)
|
36
|
+
@meths.uniq! if @meths.respond_to?(:uniq!)
|
37
|
+
@meths ||= []
|
38
|
+
end
|
39
|
+
|
40
|
+
def usage(meth_name)
|
41
|
+
"#{name.split("::")[-1].uncamelize} #{meth_name}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def describe(action, item, shortcut_item)
|
45
|
+
"#{action} #{item}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
include ::Bash
|
50
|
+
|
51
|
+
|
52
|
+
def get_options(args)
|
53
|
+
h = {}
|
54
|
+
args.select do |a|
|
55
|
+
a.match ":"
|
56
|
+
end.each do |a|
|
57
|
+
r = a.chomp.match(%r{^(\w+)\:(\w+)$})
|
58
|
+
if r && r[1] && r[2]
|
59
|
+
h[r[1].to_sym] = r[2]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
h
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_options(options, dict)
|
66
|
+
options.map do |k, v|
|
67
|
+
options[k] = dict[v.to_sym]
|
68
|
+
end
|
69
|
+
options
|
70
|
+
end
|
71
|
+
|
72
|
+
def implicit(keyword)
|
73
|
+
/^#{keyword.split("").join(".*")}.*/
|
74
|
+
end
|
75
|
+
|
76
|
+
def find(path)
|
77
|
+
Find.find(path).select { |f| test(?f, f) }
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_boolean(str)
|
81
|
+
str == "true"
|
82
|
+
end
|
83
|
+
|
84
|
+
def convert_options(options)
|
85
|
+
opts = {}
|
86
|
+
r = options.split(":")
|
87
|
+
opts[:"#{r[0]}"] = to_boolean r[1]
|
88
|
+
opts
|
89
|
+
end
|
90
|
+
|
91
|
+
def handle_drb_out(result)
|
92
|
+
Out.msgs
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
File without changes
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "thor"
|
2
|
+
Thor::Shell::Basic.class_eval do
|
3
|
+
def say(message="", color=nil, force_new_line=(message.to_s !~ /( |\t)\Z/))
|
4
|
+
message = message.to_s
|
5
|
+
|
6
|
+
message = set_color(message, *color) if color && can_display_colors?
|
7
|
+
|
8
|
+
spaces = " " * padding
|
9
|
+
|
10
|
+
if force_new_line
|
11
|
+
stdout.puts(spaces + message)
|
12
|
+
else
|
13
|
+
stdout.print(spaces + message)
|
14
|
+
end
|
15
|
+
|
16
|
+
#puts "message:#{message} line:#{__LINE__}"
|
17
|
+
$ro_out << message
|
18
|
+
end
|
19
|
+
|
20
|
+
def print_table(array, options={})
|
21
|
+
return if array.empty?
|
22
|
+
|
23
|
+
formats, indent, colwidth = [], options[:indent].to_i, options[:colwidth]
|
24
|
+
options[:truncate] = terminal_width if options[:truncate] == true
|
25
|
+
|
26
|
+
formats << "%-#{colwidth + 2}s" if colwidth
|
27
|
+
start = colwidth ? 1 : 0
|
28
|
+
|
29
|
+
colcount = array.max{|a,b| a.size <=> b.size }.size
|
30
|
+
|
31
|
+
maximas = []
|
32
|
+
|
33
|
+
start.upto(colcount - 1) do |index|
|
34
|
+
maxima = array.map {|row| row[index] ? row[index].to_s.size : 0 }.max
|
35
|
+
maximas << maxima
|
36
|
+
if index == colcount - 1
|
37
|
+
# Don't output 2 trailing spaces when printing the last column
|
38
|
+
formats << "%-s"
|
39
|
+
else
|
40
|
+
formats << "%-#{maxima + 2}s"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
formats[0] = formats[0].insert(0, " " * indent)
|
45
|
+
formats << "%s"
|
46
|
+
|
47
|
+
array.each do |row|
|
48
|
+
sentence = ""
|
49
|
+
|
50
|
+
row.each_with_index do |column, index|
|
51
|
+
maxima = maximas[index]
|
52
|
+
|
53
|
+
if column.is_a?(Numeric)
|
54
|
+
if index == row.size - 1
|
55
|
+
# Don't output 2 trailing spaces when printing the last column
|
56
|
+
f = "%#{maxima}s"
|
57
|
+
else
|
58
|
+
f = "%#{maxima}s "
|
59
|
+
end
|
60
|
+
else
|
61
|
+
f = formats[index]
|
62
|
+
end
|
63
|
+
sentence << f % column.to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
sentence = truncate(sentence, options[:truncate]) if options[:truncate]
|
67
|
+
$ro_out << sentence
|
68
|
+
stdout.puts sentence
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'find'
|
2
|
+
|
3
|
+
module RoCommands
|
4
|
+
module DSL
|
5
|
+
module File
|
6
|
+
def dir?(path)
|
7
|
+
test(?d, path)
|
8
|
+
end
|
9
|
+
|
10
|
+
# file?
|
11
|
+
def file?(path)
|
12
|
+
test(?f, path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def find(path)
|
16
|
+
Find.find(path).to_a
|
17
|
+
end
|
18
|
+
|
19
|
+
# size
|
20
|
+
def size(path)
|
21
|
+
test(?s, path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require File.expand_path('../base', __FILE__)
|
2
|
+
require 'find'
|
3
|
+
|
4
|
+
module RoCommands
|
5
|
+
class FileActions < Base
|
6
|
+
|
7
|
+
desc 'grep KEYWORD PATH [depth:Fixnum] [verbose:Boolean]', ''
|
8
|
+
|
9
|
+
def grep(keyword, path=nil, options={})
|
10
|
+
if options.is_a?(String)
|
11
|
+
options = convert_options options
|
12
|
+
end
|
13
|
+
@keyword = keyword
|
14
|
+
@path = path || Dir.pwd
|
15
|
+
@options = options
|
16
|
+
|
17
|
+
if @options[:verbose]
|
18
|
+
@match_files = []
|
19
|
+
_grep_verbose
|
20
|
+
puts_match_files
|
21
|
+
else
|
22
|
+
_grep()
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'find DIR [KEYWORD]', ''
|
27
|
+
|
28
|
+
def find(dir, keyword=nil)
|
29
|
+
Find.find(dir).each do |path|
|
30
|
+
if keyword
|
31
|
+
if path[/#{keyword}/]
|
32
|
+
puts path
|
33
|
+
end
|
34
|
+
else
|
35
|
+
puts path
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'find_railscasts', 'find railscasts'
|
41
|
+
|
42
|
+
def find_railscasts(video_name)
|
43
|
+
Find.find('/media/zxr/New-Volume/TDDOWNLOAD/railscasts/').each do |path|
|
44
|
+
if path[Regexp.new video_name]
|
45
|
+
puts path
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def puts_match_files
|
52
|
+
puts @match_files unless @match_files.empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
def _grep
|
56
|
+
if @options[:depth]
|
57
|
+
depth = []
|
58
|
+
@options[:depth].times { depth << '**' }
|
59
|
+
fs = Dir[File.join(@path, depth.join("/"))]
|
60
|
+
fs.each do |f|
|
61
|
+
grep_match(f)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
fs = Find.find(@path).map do |f|
|
65
|
+
grep_match(f)
|
66
|
+
end.compact
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def _grep_verbose
|
71
|
+
if @options[:depth]
|
72
|
+
depth = []
|
73
|
+
@options[:depth].times { depth << '**' }
|
74
|
+
fs = Dir[File.join(@path, depth.join("/"))]
|
75
|
+
fs.each do |f|
|
76
|
+
puts "greping #{f}"
|
77
|
+
grep_match(f)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
fs = Find.find(@path).map do |f|
|
81
|
+
puts "greping #{f}"
|
82
|
+
grep_match(f)
|
83
|
+
end.compact
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def grep_match(file)
|
89
|
+
@ctn = File.read file if test(?f, file)
|
90
|
+
@file = file
|
91
|
+
if test(?f, file)
|
92
|
+
match_file_name
|
93
|
+
match_file_ctn
|
94
|
+
elsif test(?d, file)
|
95
|
+
match_file_name
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def match_file_name
|
100
|
+
if @file[/#{@keyword}/]
|
101
|
+
puts @file
|
102
|
+
puts
|
103
|
+
@match_files << @file if @match_files
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def match_file_ctn
|
108
|
+
begin
|
109
|
+
r = @ctn.scan /^.*#{@keyword}.*$/
|
110
|
+
unless r.empty?
|
111
|
+
puts <<-PUTS
|
112
|
+
#{@file}:
|
113
|
+
...
|
114
|
+
#{r.join "\n"}
|
115
|
+
...
|
116
|
+
PUTS
|
117
|
+
puts
|
118
|
+
@match_files << @file if @match_files
|
119
|
+
end
|
120
|
+
rescue => e
|
121
|
+
#puts "Unknown language in #{@file}"
|
122
|
+
#puts "@file:#{@file}"
|
123
|
+
#puts "@keyword:#{@keyword}"
|
124
|
+
#puts "@ctn.encoding:#{@ctn.encoding}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|