mgit 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjEzMDA0N2Y1ODg5MDZmMmJiYmY4YTMxNjkwOGY4NGE2NTVmYWE2Yw==
4
+ ZjllZmRiNWExNjk4ZmJjZmVkNjI4ZTJhZGRiZThhOWMyYWVjNDEwZQ==
5
5
  data.tar.gz: !binary |-
6
- YjA2NTMwODQ0MGQ5YjA1MmM1ZDhhOWMxYTY0MmY0ZjM0ZDQxN2NhOA==
6
+ NzY1NmE3YWEwOWY5NjJiOGI1ZjNmMTczNjJkNTlhMjA1NDhmYmYzZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzMwMDJmODQ1YTMyOTEyZjg3NmQwODY4ZjhiNWYwOTMxYmVjMDhjMDU3MjJh
10
- NGYwNTNhYzA3NTRmZGQ0MTMwZmRhYTFmMGFjNTM1OGY4MjExYjUyY2VjZTg2
11
- YTc1YmI5M2MxZDBkZWE2YTc5ZDE2MzI0YmJjOWQ5NjMxZTgzOTQ=
9
+ ZmEyZWI3M2Y4Njg4NjkwZGU1NWRiZjk0Y2QzOWNiOWRkNjM2YjllNDg4NWVj
10
+ NmYzYjJkZWVmZjQwNWZiZjE1NDFjYjVlZGU4ZDBlYWQxYmJhMjZmZTE2ZjE4
11
+ YWQ1ODQxMzAyNzU4ZWY1ZTlhYzg3MWJkZjQ5ZmJmNzVlODFhMmE=
12
12
  data.tar.gz: !binary |-
13
- OTIwMWFiMWIzMDQ2NjE4Nzk0YjQ5OWFhMTFiMmU0MmMxZWY4YTk3YmI1MTFl
14
- MDI3OTE5NzNmMDhlMDliOGVhODRjNzU1MTcyM2M0NGVhZDdiZjcyNmE4NzNh
15
- NDQ1YjNmYTA4ZDQ3NDE5Yzc2OWJmMGViNWI5YTViNTFiN2U1MjQ=
13
+ MDUyZGY4N2I5ZGY4NTRkZmFlMmM0YTJhYmU0Y2MzOGQ0MDE5Y2QzMmRhYjE1
14
+ MzQ5NTkzZGFiMTJmYTExNzBlODI2MmYyMjA5NjAxZTZlM2I1Yzg4NDkxYmJh
15
+ OTgwYTg4NGZhMzYwM2NjZDEyZGRmMjA4ZWFhYWMzODYwZGQ5ZmM=
data/lib/mgit.rb CHANGED
@@ -4,6 +4,7 @@ require 'xdg'
4
4
 
5
5
  require 'mgit/version'
6
6
  require 'mgit/exceptions'
7
+ require 'mgit/output'
7
8
  require 'mgit/registry'
8
9
  require 'mgit/repository'
9
10
 
data/lib/mgit/command.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module MGit
2
2
  class Command
3
+ include Output
4
+
3
5
  @@commands = {}
4
6
  @@aliases = {}
5
7
 
@@ -31,20 +33,10 @@ module MGit
31
33
  end
32
34
  end
33
35
 
34
- def arity
35
- raise ImplementationError.new("Command #{self.class.name} doesn't implement the arity method.")
36
- end
37
-
38
- def usage
39
- raise ImplementationError.new("Command #{self.class.name} doesn't implement the usage method.")
40
- end
41
-
42
- def help
43
- raise ImplementationError.new("Command #{self.class.name} doesn't implement the help method.")
44
- end
45
-
46
- def description
47
- raise ImplementationError.new("Command #{self.class.name} doesn't implement the description method.")
36
+ [:arity, :usage, :help, :description].each do |meth|
37
+ define_method(meth) do
38
+ raise ImplementationError.new("Command #{self.class.name} doesn't implement the #{meth.to_s} method.")
39
+ end
48
40
  end
49
41
 
50
42
  private
@@ -5,7 +5,6 @@ module MGit
5
5
  raise GitError.new('Clone command failed.') if $?.exitstatus != 0
6
6
 
7
7
  m = /Cloning into '(.*)'/.match(log.split("\n").first)
8
- puts m[1]
9
8
  Command.execute('add', [m[1]])
10
9
  end
11
10
 
@@ -3,7 +3,7 @@ module MGit
3
3
  def execute(args)
4
4
  Registry.chdir_each do |repo|
5
5
  `git remote`.split.each do |remote|
6
- puts "Fetching #{remote} in repository #{repo.name}...".yellow
6
+ pinfo "Fetching #{remote} in repository #{repo.name}..."
7
7
  `git fetch #{remote}`
8
8
  end
9
9
  end
@@ -3,11 +3,11 @@ module MGit
3
3
  def execute(args)
4
4
  Registry.chdir_each do |repo|
5
5
  if repo.dirty?
6
- puts "Skipping repository #{repo.name} since it's dirty.".red
6
+ pwarn "Skipping repository #{repo.name} since it's dirty."
7
7
  next
8
8
  end
9
9
 
10
- puts "Fast-forward merging branches in repository #{repo.name}...".yellow
10
+ pinfo "Fast-forward merging branches in repository #{repo.name}..."
11
11
 
12
12
  cb = repo.current_branch
13
13
  repo.remote_tracking_branches.each do |b, u|
@@ -4,7 +4,7 @@ module MGit
4
4
  command = args.join(' ')
5
5
 
6
6
  Registry.chdir_each do |repo|
7
- puts "Executing command in repository #{repo.name}...".yellow
7
+ pinfo "Executing command in repository #{repo.name}..."
8
8
  if !system(command) && !ask("Executing command '#{command}' in repository '#{repo.name}' failed. Would you like to continue anyway?".red)
9
9
  break
10
10
  end
@@ -4,7 +4,7 @@ module MGit
4
4
  ptrn = args[0]
5
5
 
6
6
  Registry.chdir_each do |repo|
7
- puts "Looking for pattern '#{ptrn}' in repository #{repo.name}...".yellow
7
+ pinfo "Looking for pattern '#{ptrn}' in repository #{repo.name}..."
8
8
  puts `git grep #{ptrn}`
9
9
  puts
10
10
  end
@@ -2,14 +2,14 @@ module MGit
2
2
  class HelpCommand < Command
3
3
  def execute(args)
4
4
  if args.size == 0
5
- puts "M[eta]Git - manage multiple git repositories at the same time"
5
+ pinfo "M[eta]Git - manage multiple git repositories at the same time"
6
6
  puts
7
- puts "Usage:"
7
+ pinfo "Usage:"
8
8
  Command.instance_each do |cmd|
9
- puts "mgit #{cmd.usage}\n\t- #{cmd.description}"
9
+ pinfo "mgit #{cmd.usage}\n\t- #{cmd.description}"
10
10
  end
11
11
  else
12
- puts Command.create(args[0]).help
12
+ pinfo Command.create(args[0]).help
13
13
  end
14
14
  end
15
15
 
@@ -1,11 +1,9 @@
1
1
  module MGit
2
2
  class ListCommand < Command
3
3
  def execute(args)
4
- Registry.each do |repo|
5
- nc = 24
6
- display = (repo.name.size > nc) ? (repo.name[0..(nc - 3)] + '...') : repo.name.ljust(nc, ' ')
7
- puts "#{display} => #{repo.path}"
8
- end
4
+ t = []
5
+ Registry.each { |repo| t << [repo.name, repo.path] }
6
+ ptable t, :columns => [24, nil]
9
7
  end
10
8
 
11
9
  def arity
@@ -6,11 +6,11 @@ module MGit
6
6
  uc = unmerged_commits(branch, upstream)
7
7
  next if uc.empty?
8
8
 
9
- puts "In repository #{repo.name}, branch #{upstream} the following commits were made:".yellow
10
- longest_name = uc.map { |c| c[:author].size }.max
11
- uc.each do |c|
12
- puts "#{c[:commit]} #{c[:author].ljust(longest_name, ' ')} #{c[:subject]}"
13
- end
9
+ pinfo "In repository #{repo.name}, branch #{upstream} the following commits were made:"
10
+
11
+ t = []
12
+ uc.each { |c| t << [c[:commit], c[:author], c[:subject]] }
13
+ ptable t
14
14
  end
15
15
  end
16
16
  end
@@ -10,7 +10,7 @@ module MGit
10
10
  raise CommandUsageError.new("Couldn't find repository matching '#{ptrn}'.", self) unless repo
11
11
 
12
12
  Registry.remove(repo.name)
13
- puts "Removed repository #{repo.name}.".yellow
13
+ pinfo "Removed repository #{repo.name}."
14
14
  end
15
15
 
16
16
  def arity
@@ -3,11 +3,9 @@ require 'set'
3
3
  module MGit
4
4
  class StatusCommand < Command
5
5
  def execute(args)
6
- Registry.chdir_each do |repo|
7
- nc = 36
8
- display = (repo.name.size > nc) ? (repo.name[0..(nc - 3)] + '...') : repo.name.ljust(nc, ' ')
9
- puts "#{display} => [#{flags(repo).to_a.join(', ')}]"
10
- end
6
+ t = []
7
+ Registry.chdir_each { |repo| t << [repo.name, flags(repo).to_a.join(', ')] }
8
+ ptable t, :columns => [24, nil]
11
9
  end
12
10
 
13
11
  def arity
@@ -1,7 +1,7 @@
1
1
  module MGit
2
2
  class VersionCommand < Command
3
3
  def execute(args)
4
- puts "mgit version #{MGit::VERSION}"
4
+ pinfo "mgit version #{MGit::VERSION}"
5
5
  end
6
6
 
7
7
  def arity
@@ -0,0 +1,73 @@
1
+ module MGit
2
+ module Output
3
+ def pinfo(s)
4
+ puts s.green
5
+ end
6
+
7
+ def pwarn
8
+ puts s.yellow
9
+ end
10
+
11
+ def perror
12
+ puts s.red
13
+ end
14
+
15
+ def ptable(table, options = {})
16
+ puts TableOutputter.new(table, options).to_s
17
+ end
18
+
19
+ private
20
+
21
+ class TableOutputter
22
+ attr_reader :table, :options
23
+
24
+ def initialize(table, options)
25
+ @table = table
26
+ @options = options
27
+ raise ImplementationError.new('ptable called with invalid table') unless valid_table?
28
+ end
29
+
30
+ def to_s
31
+ cw = column_widths
32
+
33
+ if options[:columns]
34
+ options[:columns].each_with_index do |c, i|
35
+ cw[i] = c if c
36
+ end
37
+ end
38
+
39
+ table.map do |row|
40
+ row.map.with_index { |cell, i| justify(cell, cw[i]) }.join(' | ')
41
+ end.join("\n")
42
+ end
43
+
44
+ private
45
+
46
+ def valid_table?
47
+ table.empty? || table.all? { |c| c.is_a?(Array) && c.size == table.first.size }
48
+ end
49
+
50
+ def columns
51
+ table.first.size
52
+ end
53
+
54
+ def column(nth)
55
+ table.map { |c| c[nth] }
56
+ end
57
+
58
+ def transpose
59
+ (0..(columns - 1)).map { |i| column(i) }
60
+ end
61
+
62
+ def column_widths
63
+ transpose.map do |col|
64
+ col.map { |cell| cell.size }.max
65
+ end
66
+ end
67
+
68
+ def justify(s, n)
69
+ (s.size > n) ? (s[0..(n - 3)] + '...') : s.ljust(n, ' ')
70
+ end
71
+ end
72
+ end
73
+ end
data/lib/mgit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MGit
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - FlavourSys Technology GmbH
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - lib/mgit/exceptions.rb
63
+ - lib/mgit/output.rb
63
64
  - lib/mgit/cli.rb
64
65
  - lib/mgit/command.rb
65
66
  - lib/mgit/commands/clone.rb