Class: Eo
- Inherits:
-
Object
show all
- Extended by:
- Gem
- Defined in:
- lib/eo.rb,
lib/eo/eo.rb
Constant Summary
collapse
- Repos =
Hash.new
- Config =
{'open' => 'vim','shell' => 'sh'}.merge(
File.exist?(config_file) ? YAML.load_file(config_file) : {}
)
Class Method Summary
collapse
Methods included from Gem
gemopen, gemshell, gemshow
Class Method Details
.choose(args) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/eo/eo.rb', line 30
def choose(args)
repos = pick(:key => args)
if repos && repos = repos.first return false unless exist_path(repos)
loop do
input = (readline("\e[01;34m#{repos} (h:help)>> \e[0m",true) || exit).rstrip
break if input =~ /\A\s*q\s*\Z/
exit if input =~ /\A\s*Q\s*\Z/
Repos[repos].send(input) unless input.empty?
end
end
end
|
.delete(args, opt = {}) ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/eo/eo.rb', line 68
def delete(args,opt={})
repos = pick(:key => args,:plural => true)
repos.each do |x|
puts "\e[32m Deleting #{Repos[x]._name_}:\e[0m"
Repos[x].delete
end
end
|
.execute(args) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/eo.rb', line 21
def execute(args)
params = (args.size > 1) ? args[1,args.size].join : ''
case args.first
when /^-gs$/i then gemshow(params)
when /^-gc$/i then gemshell(params)
when /^-go$/i then gemopen(params)
when /^-s\w?$/i then show(params, :skip => (args[0] =~ /^-sa$/).nil?)
when /^-i\w?$/i then init(params, :skip => (args[0] =~ /^-ia$/).nil?)
when /^-u\w?$/i then update(params,:skip => (args[0] =~ /^-ua$/).nil?)
when /^-p\w?$/i then push(params, :skip => (args[0] =~ /^-pa$/).nil?)
when /^-o$/i then open(params)
when /^-c$/i then choose(params)
when /^-d$/i then delete(params)
when /^-t$/i then type
when /^-v$/i then puts "\e[33mEo_oE : v#{Easyoperate::VERSION}\e[0m"
when /^-(h|help)$/i then help
else self.run
end
end
|
.help(shell = true) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/eo.rb', line 73
def help(shell=true)
puts <<-DOC.gsub(/^(\s*)/,'').gsub(/^\|(\s*)/,'\1' + (shell ? '-':''))
Usage:
| I /args/ : Initialize matched Repository <Regexp>
| U /args/ : Update matched Repository <Regexp>
| T : Show All Support Scm
| P /args/ : Push All pushable repositories <Regexp>
| S /args/ : Show matched repositories <Regexp>
| O /args/ : Open The repository's path <Regexp>
| C /args/ : Choose One Repository <Regexp>
| D /args/ : Delete Repository <Regexp>
| GS /args/ : Show matched Gems <Regexp>
| GC /args/ : Choose One Gem <Regexp>
| GO /args/ : Open The Gem's Path <Regexp>
| Q : Quit
| H : Show this help message.
| V : Show version information.
#{shell ? "e.g: \n \e[032m $ eo -S v.*m\e[0m" :
"e.g:\n \e[32m s v.*m\e[0m" }
DOC
end
|
.init(args, opt = {}) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/eo/eo.rb', line 45
def init(args,opt={})
repos = pick(:key => args,:plural => true,:skip => opt[:skip])
repos.each do |x|
if Repos[x].path && File.exist?(Repos[x].path)
puts "\e[32m %-18s: already Initialized\e[0m" % [x]
else
puts "\e[32m %-18s: Initializing\e[0m" % [x]
Repos[x].init
end
end
end
|
.open(args) ⇒ Object
25
26
27
28
|
# File 'lib/eo/eo.rb', line 25
def open(args)
repos = pick(:key => args)
system([Config['open'],Repos[repos.first].path].join(' ')) if repos
end
|
.push(args, opt = {}) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/eo/eo.rb', line 58
def push(args,opt={})
repos = pick(:key => args,:plural => true,:pushable => true,:skip => opt[:skip])
repos.each do |x|
puts "\e[32m %-18s: Pushing\e[0m" % [x]
next if !exist_path(x)
Repos[x].push if Repos[x].respond_to?(:push)
end
end
|
.run ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/eo.rb', line 45
def run
loop do
input = (readline("\e[33mInput Commands (q:quit h:help): \e[0m",true) || exit).rstrip.split(' ',2)
case input[0].to_s
when /^GS$/i then gemshow(input[1])
when /^GC$/i then gemshell(input[1])
when /^GO$/i then gemopen(input[1])
when /^S\w?/i then show(input[1], :skip =>(input[0] =~ /^sa$/i).nil?)
when /^I\w?/i then init(input[1], :skip =>(input[0] =~ /^ia$/i).nil?)
when /^U\w?/i then update(input[1],:skip =>(input[0] =~ /^ua$/i).nil?)
when /^P\w?/i then push(input[1], :skip =>(input[0] =~ /^pa$/i).nil?)
when /^O$/i then open(input[1])
when /^C$/i then choose(input[1])
when /^D$/i then delete(input[1])
when /^T$/i then type
when /^P$/i then push(input[1])
when /^Q$/i then exit
when /^V$/i then
puts "\e[33mEo_oE : v" + Easyoperate::VERSION + "\e[0m"
when /^H|HELP$/i then help
else puts "\e[31mError Command\e[0m"
end
end
end
|
.show(args, opt = {}) ⇒ Object
19
20
21
22
23
|
# File 'lib/eo/eo.rb', line 19
def show(args,opt={})
puts "\e[33mAll Repo match < #{args} > :\e[0m"
repos = pick(:key => args,:plural => true,:skip => opt[:skip])
format_display(repos) if repos
end
|
.type ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/eo/eo.rb', line 5
def type
puts "\e[33mAll Scm-type :\e[0m"
["#{ENV['HOME']}/.eo/scm/",File.dirname(__FILE__) + '/scm' ].each do |x|
next if !File.exist?(x)
(@scm ||= []).concat(Dir.new(x).entries.reject {|i| i =~/^\.+$/})
end
@scm.uniq.map do |x|
(@formated_scm ||= []) << File.basename(x,".rb")
end
format_display(@formated_scm)
end
|
.update(args, opt = {}) ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'lib/eo/eo.rb', line 77
def update(args,opt={})
repos = pick(:key => args,:plural => true,:skip => opt[:skip])
repos.each do |x|
puts "\e[32m Updating #{Repos[x]._name_}:\e[0m"
next if !exist_path(x)
Repos[x].update
end
end
|