easyoperate 0.1.2 → 0.2.0

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.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2.0 2008-12-22
2
+
3
+ * 1 major enhancement:
4
+ * Scm Plugin (Add your SCM Plugin to ~/.eo/scm )
5
+
1
6
  == 0.1.0 2008-12-13
2
7
 
3
8
  * 1 major enhancement:
data/Manifest.txt CHANGED
@@ -7,7 +7,9 @@ example/eorc
7
7
  lib/easyoperate.rb
8
8
  lib/eo.rb
9
9
  lib/eo/eo.rb
10
- lib/eo/scm.rb
10
+ lib/eo/repository.rb
11
+ lib/eo/scm/git.rb
12
+ lib/eo/scm/svn.rb
11
13
  test/test_easyoperate.rb
12
14
  test/test_eo_cli.rb
13
15
  test/test_helper.rb
data/README.rdoc CHANGED
@@ -17,7 +17,7 @@
17
17
  # then copy autoload/rails.vim to ~/.vim/autoload/
18
18
  # then copy plugin/rails.vim to ~/.vim/plugin/
19
19
 
20
- scm: # svn/git,default is git
20
+ scm: # Default is git,your can define your scm-type in ~/.eo/scm
21
21
 
22
22
  cmd: # Where you can define your methods
23
23
  cp_autoload: `cp autoload/rails.vim ~/.vim/autoload/`
data/bin/eo CHANGED
@@ -3,8 +3,15 @@
3
3
  # Copyright (c) 2008. GPL3.
4
4
  # Author: Jinzhu Zhang
5
5
 
6
- require File.expand_path(File.dirname(__FILE__) + "/../lib/easyoperate")
7
-
6
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
7
+ require "easyoperate"
8
8
  require "eo"
9
9
 
10
- Eo.execute(STDOUT, ARGV)
10
+ # easy debug
11
+ if ARGV.delete('-d')
12
+ ['rubygems','ruby-debug'].each {|x| require x}
13
+ else
14
+ def debugger;end
15
+ end
16
+
17
+ Eo.execute(ARGV)
data/lib/easyoperate.rb CHANGED
@@ -1,5 +1,3 @@
1
- $LOAD_PATH << File.dirname(__FILE__)
2
-
3
1
  module Easyoperate
4
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
5
3
  end
data/lib/eo.rb CHANGED
@@ -1,49 +1,29 @@
1
- %w(optparse yaml eo/eo).each {|f| require f}
1
+ %w(yaml eo/eo).each {|f| require f}
2
2
 
3
3
  class Eo
4
4
 
5
- def self.execute(stdout, arguments=[])
6
-
7
- parser = OptionParser.new do |opts|
8
- opts.banner = <<-BANNER.gsub(/^ /,'')
9
- Usage: #{File.basename($0)} [options] [ARGS]
10
-
11
- Options are:
12
- BANNER
13
-
14
- opts.on_tail("-h", "--help","Show this help message.") do |args|
15
- stdout.puts opts; exit
16
- end
17
-
18
- opts.on_tail("-v", "--version","Show version information.") do
19
- puts "\e[33mEo_oE : v" + Easyoperate::VERSION + "\e[0m"; exit
20
- end
21
-
22
- opts.on("-u [ARGS]", "--update","Update Repository. <Regexp>") do |args|
23
- self.update(args)
24
- end
25
-
26
- opts.on("-s [ARGS]", "--show","Show All Repositories. <Regexp>") do |args|
27
- self.show(args)
28
- end
29
-
30
- opts.on("-c [ARGS]", "--choose","Choose Repository.") do |args|
31
- self.choose(args)
32
- end
33
-
34
- opts.on("-i [ARGS]", "--init","Initialize Repository. <Regexp>") do |args|
35
- self.init(args)
36
- end
37
-
38
- if arguments.empty?
39
- self.run
40
- else
41
- begin
42
- opts.parse!(arguments)
43
- rescue OptionParser::InvalidOption
44
- puts "\e[31m;(\tError\e[0m \n\tHelp?\t\e[33m$ eo -h \e[31m;)\e[0m"
45
- end
46
- end
5
+ def self.execute(args)
6
+
7
+ case args.first
8
+ when "-s" then self.show(args[1,args.size])
9
+ when "-c" then self.choose(args[1,args.size])
10
+ when "-i" then self.init(args[1,args.size])
11
+ when "-u" then self.update(args[1,args.size])
12
+ when "-t" then self.type
13
+ when "-v" then puts "\e[33mEo_oE : v" + Easyoperate::VERSION + "\e[0m"
14
+ when "-h" then
15
+ puts <<-DOC.gsub(/^(\s*\|)/,'')
16
+ |Usage: #{File.basename($0)} [options] [ARGS]
17
+
18
+ |Options are:
19
+ | -u Update Repository. <Regexp>
20
+ | -s Show All Repositories. <Regexp>
21
+ | -v Show version information.
22
+ | -c Choose Repository.
23
+ | -t Show All Support Scm
24
+ | -i Initialize Repository. <Regexp>
25
+ DOC
26
+ else self.run
47
27
  end
48
28
  end
49
29
  end
data/lib/eo/eo.rb CHANGED
@@ -1,17 +1,18 @@
1
- require 'eo/scm'
1
+ require File.join(File.dirname(__FILE__),'repository')
2
+
2
3
  class Eo
3
- Repo = Hash.new
4
+ Repos = Hash.new
4
5
 
5
6
  Config_file = File.join("#{ENV['HOME']}",".eorc")
6
7
 
7
8
  unless File.exist?(Config_file)
8
- puts " \e[31m;( No config file\e[0m \n\nexample file:"
9
+ puts " \e[31m;( No config file\e[0m \n\nExample Config file:\n\n"
9
10
  puts File.read(File.join(File.dirname(__FILE__),'../../example/eorc'))
10
11
  exit
11
12
  end
12
13
 
13
- YAML.load_file(Config_file).each_pair do |keys,value|
14
- Repo[keys] = Scm.new.merge(value)
14
+ YAML.load_file(Config_file).each_pair do |key,value|
15
+ Repos[key] = Repository.new(value.merge(:_name_ => key))
15
16
  end
16
17
 
17
18
  class << self
@@ -26,76 +27,92 @@ class Eo
26
27
  when /C/i then choose(input[1])
27
28
  when /U/i then update(input[1])
28
29
  when /I/i then init(input[1])
29
- when /Q/i then exit(0)
30
+ when /T/i then type
31
+ when /Q/i then exit
30
32
  else help
31
33
  end
32
34
  end
33
35
  end
34
36
 
35
37
  def help
36
- puts "Usage:"
37
- puts " S /args/ : Show matched repositories <Regexp>"
38
- puts " C /args/ : Choose One Repository <Regexp>"
39
- puts " U /args/ : Update matched Repository <Regexp>"
40
- puts " I /args/ : Initialize matched Repository <Regexp>"
41
- puts " Q : Quit"
42
- puts " H : Show this help message."
43
- puts "e.g:\n \e[32m s v.*m\e[0m"
38
+ puts <<-DOC.gsub(/^(\s*\|)/,'')
39
+ |Usage:
40
+ | S /args/ : Show matched repositories <Regexp>
41
+ | C /args/ : Choose One Repository <Regexp>
42
+ | U /args/ : Update matched Repository <Regexp>
43
+ | I /args/ : Initialize matched Repository <Regexp>
44
+ | T : Show All Support Scm
45
+ | Q : Quit
46
+ | H : Show this help message.
47
+ |e.g:\n \e[32m s v.*m\e[0m
48
+ DOC
49
+ end
50
+
51
+ def type
52
+ ["#{ENV['HOME']}/.eo/scm/",File.join(File.dirname(__FILE__),'scm')].each do |x|
53
+ next if !File.exist?(x)
54
+ (@scm ||= []).concat(Dir.new(x).entries.reject {|i| i =~/^\.+$/})
55
+ end
56
+
57
+ puts "\e[33mAll Scm-type :\e[0m"
58
+ @scm.uniq.map do |x|
59
+ (@formated_scm ||= []) << File.basename(x,".rb")
60
+ end
61
+ format_display(@formated_scm)
44
62
  end
45
63
 
46
64
  def show(*args)
47
65
  repos = pick(args,false)
48
66
  puts "\e[33mAll Repo match < #{args} > :\e[0m"
49
- repos.each_index do |x|
50
- printf "\e[32m %-22s\e[0m" % [repos[x].rstrip]
51
- printf("\n") if (x+1)%3==0
52
- end
53
- puts "\n" if repos.size%3 != 0
67
+ format_display(repos)
54
68
  end
55
69
 
56
70
  def choose(*args)
57
71
  repos = pick(args)
58
- if repos && repos = repos.to_s
72
+
73
+ if repos && repos = repos.to_s # Convert Array To String
59
74
  return false unless exist_path(repos)
60
75
  loop do
61
- printf("\e[01;34m#{repos.first} (h:help)>> \e[0m")
76
+ printf("\e[01;34m#{repos} (h:help)>> \e[0m")
62
77
  input = STDIN.gets.strip
63
78
  break if input =~ /\A\s*q\s*\Z/
64
79
  exit if input =~ /\A\s*Q\s*\Z/
65
- Repo[repos].send(input) unless input.empty?
80
+ Repos[repos].send(input) unless input.empty?
66
81
  end
67
82
  end
68
83
  end
69
84
 
70
85
  def init(*args)
71
86
  repos = pick(args,false)
87
+
72
88
  repos.each do |x|
73
- if File.exist?(File.expand_path(Repo[x]['path']))
89
+ if File.exist?(File.expand_path(Repos[x].path))
74
90
  puts "\e[32m %-18s: already Initialized\e[0m" % [x]
75
91
  next
76
92
  end
77
93
  puts "\e[32m %-18s: Initializing\e[0m" % [x]
78
- Repo[x].init
94
+ Repos[x].init
79
95
  end
80
96
  end
81
97
 
82
98
  def update(*args)
83
99
  repos = pick(args,false)
100
+
84
101
  repos.each do |x|
85
- puts "\e[32m Updating #{Repo[x]['path']}:\e[0m"
102
+ puts "\e[32m Updating #{Repos[x].path}:\e[0m"
86
103
  next if !exist_path(x)
87
- Repo[x].update
104
+ Repos[x].update
88
105
  end
89
106
  end
90
107
 
91
108
  protected
92
- def pick(args,only_one=true)
93
- repos = Repo.keys.grep(/#{args}/)
94
- if only_one
109
+ def pick(args,single=true)
110
+ repos = Repos.keys.grep(/#{args}/)
111
+ if single
95
112
  if repos.size == 1
96
113
  return repos
97
114
  elsif repos.empty?
98
- printf("\e[31mSorry,But No Result.\n\e[0m")
115
+ printf("\e[31mNo Result About < #{args} >.\n\e[0m")
99
116
  return false
100
117
  else
101
118
  return choose_one(repos)
@@ -108,18 +125,14 @@ class Eo
108
125
  def choose_one(args)
109
126
  puts "\e[33mPlease Choose One of them : \e[0m"
110
127
 
111
- args.each_index do |x|
112
- printf "\e[32m%-2d\e[0m %-22s" % [x+1,args[x].rstrip]
113
- printf "\n" if (x+1)%3 == 0
114
- end
115
- printf "\n" if args.size%3 != 0
128
+ format_display(args)
116
129
 
117
130
  num = choose_range(args.size)
118
131
  return num ? [args[num-1]] : false
119
132
  end
120
133
 
121
134
  def choose_range(size)
122
- printf "\e[33mPlease Input A Valid Number (1..#{size}) (q to quit): \e[0m"
135
+ printf "\e[33mPlease Input A Valid Number (1-#{size}) (q:quit): \e[0m"
123
136
  num = STDIN.gets
124
137
  return false if num =~ /q/i
125
138
  choosed_num = num.strip.empty? ? 1 : num.to_i
@@ -127,13 +140,20 @@ class Eo
127
140
  end
128
141
 
129
142
  def exist_path(repos)
130
- if File.exist?(File.expand_path(Repo[repos]['path']))
131
- Dir.chdir(File.expand_path(Repo[repos]['path']))
143
+ if File.exist?(File.expand_path(Repos[repos].path))
144
+ Dir.chdir(File.expand_path(Repos[repos].path))
132
145
  else
133
146
  puts "\n l.l,Have You init \e[33m#{repos}\e[0m Repository?\n\n"
134
147
  return false
135
148
  end
136
149
  end
137
150
 
151
+ def format_display(args)
152
+ args.each_index do |x|
153
+ printf "\e[32m%-2d\e[0m %-22s" % [x+1,args[x].rstrip]
154
+ printf "\n" if (x+1)%3 == 0
155
+ end
156
+ puts "\n" if args.size%3 != 0
157
+ end
138
158
  end
139
159
  end
@@ -0,0 +1,66 @@
1
+ $LOAD_PATH.unshift("#{ENV['HOME']}/.eo/",File.join(File.dirname(__FILE__)))
2
+
3
+ class Repository
4
+ attr_accessor :repo,:path,:_name_,:autorun
5
+
6
+ def initialize(opt={})
7
+
8
+ ['repo','path','_name_','autorun'].each do |x|
9
+ eval "self.#{x} = opt.delete('#{x}')"
10
+ end
11
+
12
+ begin
13
+ scm = opt['scm'] || 'git'
14
+ require "scm/#{scm.downcase}"
15
+ extend eval "Scm::#{scm.capitalize}"
16
+ rescue LoadError
17
+ puts <<-DOC.gsub(/^(\s*\|)/,'')
18
+ |\e[33m#{opt[:_name_]}\e[0m
19
+ | \e[31mSorry,doesn't support < #{scm} > now.\e[0m
20
+ | \e[31mYou can define your Scm-Type in ~/.eo/scm.\e[0m
21
+ DOC
22
+ exit 0
23
+ end
24
+
25
+ if opt['cmd'] # Define Your Methods
26
+ opt['cmd'].each do |key,value|
27
+ self.class.send(:define_method, key, lambda { eval(value) } )
28
+ (@defined_methods ||= [] ) << [key,value]
29
+ end
30
+ end
31
+ end
32
+
33
+ def help
34
+ if @defined_methods
35
+ printf("Your Defined Methods :\n")
36
+ @defined_methods.each do |x|
37
+ puts " %-18s: %s" % [x.first, x.last]
38
+ end
39
+ end
40
+
41
+ puts <<-DOC.gsub(/^\s*\|/,'')
42
+ |Usage:
43
+ | update Update
44
+ | shell/sh Goto shell
45
+ | help/h Show this help message
46
+ | q Quit this shell
47
+ | Q Exit this program
48
+ | <Hash Method> Run
49
+ | <Your Method> Run.if undefined by above
50
+ | <Shell Command> Run.if undefined by above
51
+ |e.g:\n \e[32m pwd \e[0m => The repository's path
52
+ DOC
53
+ end
54
+ alias h help
55
+
56
+ def shell
57
+ system("sh")
58
+ end
59
+ alias sh shell
60
+
61
+ def method_missing(m,*args)
62
+ # method missing -> shell command
63
+ result = system(m.to_s + " " + args.join(' '))
64
+ puts "\e[31mlol, Some Wrong?\e[0m" unless result
65
+ end
66
+ end
data/lib/eo/scm/git.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Scm
2
+ module Git
3
+ def init
4
+ system("git clone #{self.repo} #{self.path}")
5
+ end
6
+
7
+ def update
8
+ old_commit = now_commit
9
+ system("git pull")
10
+ new_commit = now_commit
11
+ if new_commit != old_commit && self.autorun
12
+ self.autorun.split(';').each do |x|
13
+ eval x
14
+ end
15
+ end
16
+ end
17
+
18
+ def now_commit
19
+ return `git log --pretty=format:%H -1`
20
+ end
21
+ end
22
+ end
data/lib/eo/scm/svn.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Scm
2
+ module Svn
3
+ def init
4
+ system("svn co #{self.repo} #{self.path}")
5
+ end
6
+
7
+ def update
8
+ old_commit = now_commit
9
+ system("svn update")
10
+ new_commit = now_commit
11
+ if new_commit != old_commit && self.autorun
12
+ self.autorun.split(';').each do |x|
13
+ eval x
14
+ end
15
+ end
16
+ end
17
+
18
+ def now_commit
19
+ return `svn -l 1 log -q | sed '1d;3d' | awk '{print $1}'`
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easyoperate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jinzhu Zhang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-14 00:00:00 +08:00
12
+ date: 2008-12-22 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.2.0
23
+ version: 1.2.1
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
@@ -53,7 +53,9 @@ files:
53
53
  - lib/easyoperate.rb
54
54
  - lib/eo.rb
55
55
  - lib/eo/eo.rb
56
- - lib/eo/scm.rb
56
+ - lib/eo/repository.rb
57
+ - lib/eo/scm/git.rb
58
+ - lib/eo/scm/svn.rb
57
59
  - test/test_easyoperate.rb
58
60
  - test/test_eo_cli.rb
59
61
  - test/test_helper.rb
data/lib/eo/scm.rb DELETED
@@ -1,89 +0,0 @@
1
- class Scm < Hash
2
-
3
- def help
4
- if self['cmd'] && cmd = self['cmd'].keys
5
- printf("Your Defined Methods :\n")
6
- cmd.each_index do |x|
7
- puts " %-18s: %s" % [cmd[x].rstrip,self['cmd'][cmd[x]]]
8
- end
9
- puts
10
- end
11
-
12
- puts "Usage: "
13
- puts " %-18s: %s." % ["update","Update"]
14
- puts " %-18s: %s." % ["shell/sh","Goto shell"]
15
- puts " %-18s: %s." % ["help/h","Show this help message"]
16
- puts " %-18s: %s." % ["q","Quit this shell"]
17
- puts " %-18s: %s." % ["Q","Exit this program"]
18
- puts " %-18s: %s." % ["<Hash Method>","Run"]
19
- puts " %-18s: %s." % ["<Your Method>","Run.if undefined by above"]
20
- puts " %-18s: %s." % ["<Shell Command>","Run.if undefined by above"]
21
- puts "e.g:\n \e[32m pwd \e[0m => The repository's path"
22
-
23
- end
24
- alias h help
25
-
26
- def update
27
- old_commit = now_commit
28
- scm_update
29
- new_commit = now_commit
30
- if new_commit != old_commit && self['autorun']
31
- self['autorun'].split(';').each do |x|
32
- eval x
33
- end
34
- end
35
- end
36
-
37
- def shell
38
- system("sh")
39
- end
40
- alias sh shell
41
-
42
- def init
43
- command = case self['scm']
44
- when /svn/ then 'svn co'
45
- when /git/ then 'git clone'
46
- when nil then 'git clone'
47
- end
48
- if command
49
- system("#{command} #{self['repo']} #{self['path']}")
50
- else
51
- puts "\e[31mSorry,Maybe doesn't support #{self['scm']} rightnow.\e[0m"
52
- end
53
- end
54
-
55
- def method_missing(m,*args)
56
- m = m.to_s
57
- methods = self['cmd'] ? self['cmd'].keys.grep(m) : []
58
-
59
- if methods.size == 1
60
- eval self['cmd'][m]
61
- else
62
- result = system(m + " " + args.join(' '))
63
- puts "\e[31mlol, Some Wrong?\e[0m" unless result
64
- end
65
- end
66
-
67
- protected
68
- def scm
69
- return 'git' if !Dir.entries('.').grep(".git").empty?
70
- return 'svn' if !Dir.entries('.').grep(".svn").empty?
71
- end
72
-
73
- def scm_update
74
- case scm
75
- when /git/ then system("git pull")
76
- when /svn/ then system("svn update")
77
- end
78
- end
79
-
80
- def now_commit
81
- case scm
82
- when /git/ then return `git log --pretty=format:%H -1`
83
- when /svn/ then return `svn -l 1 log -q | grep "\w" | awk '{print $1}'`
84
- else
85
- puts "\e[31mSorry,Only Support SVN/GIT\e[0m"
86
- exit
87
- end
88
- end
89
- end