r-git 1.1 → 1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b9b8b71821185add335a94f2b6cb8b36a54b769
4
- data.tar.gz: 0fedb11778194aebeb7ea22d62aad4e04975f848
3
+ metadata.gz: a1c3c72baf1287072aa53b4100a22dadeb09b5df
4
+ data.tar.gz: aff200aa42a7e921d4ed29eeaf05592ce4e52b4b
5
5
  SHA512:
6
- metadata.gz: a39436aa0aa0c0d786ddc8955c53e884cc489360b79d5248dac56195382c9a520fde0bde227f6ccd0008736decf0fede53a15eb290ad85184fb7e30a5fd9ab3e
7
- data.tar.gz: 620463392c4514f91755e129271aa92cadfc5b4a0c540077f12fe377521b143c5187f1c6d6c21f338da51a94ec8bb82c3350ec60b724328a72932a1274665532
6
+ metadata.gz: 3b5183f8e1ef149f5a2a8c26165f9044a44afc4148c4c1c4eff725bf0212a816ec6f2405b55ffc90abc44194065a7caa20d4aeda02540cd398a07149a5e2e8fd
7
+ data.tar.gz: 42b80f19cac4f77df0a831d66778a574218997fbf510476a65fb17ba658da073b50e5f83cdc98d5f777096a30cedff9602f4f5ff18b94fd9a705c10fd0817486
data/.rubocop.yml CHANGED
@@ -11,7 +11,4 @@ Metrics/CyclomaticComplexity:
11
11
  Metrics/LineLength:
12
12
  Max: 120
13
13
  Metrics/MethodLength:
14
- Max: 40
15
- Metrics/PerceivedComplexity:
16
- Exclude:
17
- - lib/rgit/cli.rb
14
+ Max: 40
data/CHANGELOG.md CHANGED
@@ -1,9 +1,15 @@
1
1
  ## Change Log
2
2
 
3
+ ### 1.2
4
+ * Fixed ```bin/console```
5
+ * Re-factored Cli class and added help/usage information for subcommands
6
+ * Added internationalization support (via i18n)
7
+
3
8
  ### 1.1
4
9
  * Added travis configuration
5
10
  * Added code climate configuration
6
11
  * Increased test coverage and code quality
7
12
  * Moved to sub-commands
13
+
8
14
  ### 1.0.2
9
15
  * Initial Version
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'rgit'
4
+ require 'rgit/rgit'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
data/exe/rgit CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'rgit/rgit'
4
- Rgit::Cli.parse(ARGV)
3
+ require 'i18n'
4
+ include Rgit
5
+ I18n.load_path << File.expand_path('../../locales/en.yml', __FILE__)
6
+ I18n.reload!
7
+
8
+ rgit = Rgit::Rgit.new(Configuration.exist? ? Configuration.load : Configuration.create)
9
+ Rgit::Cli.new(rgit).parse(ARGV)
data/lib/rgit/cli.rb CHANGED
@@ -6,44 +6,102 @@ module Rgit
6
6
 
7
7
  SUB_COMMANDS = %w(add-root remove-root show-roots checkout pull fetch status version).freeze
8
8
 
9
- def self.parse(args, rgit = Rgit.new(Configuration.exist? ? Configuration.load : Configuration.create))
10
- global_opts = Trollop.options(args) do
11
- banner 'rgit is a utility for managing multiple git repositories'
12
- opt :verbose, 'Run verbosely', short: '-v'
13
- stop_on SUB_COMMANDS
14
- end
9
+ def initialize(rgit)
10
+ @rgit = rgit
11
+ end
12
+
13
+ def parse(args)
14
+ parser = rgit_argument_parser
15
+ global_opts = get_global_options(parser, args)
15
16
 
16
- rgit.verbose = global_opts[:verbose]
17
+ @rgit.verbose = global_opts[:verbose]
17
18
 
18
19
  cmd = args.shift
19
20
  case cmd
20
21
  when 'add-root'
21
- path = args.size == 1 ? args[0] : Dir.pwd
22
- rgit.add_root(path)
22
+ add_root(args)
23
23
  when 'remove-root'
24
- path = args.size == 1 ? args[0] : Dir.pwd
25
- rgit.remove_root(path)
24
+ remove_root(args)
26
25
  when 'checkout'
27
- branch = args[0] if args.size == 1
28
- unless branch
29
- puts 'ERROR: checkout subcommand expects a branch name'.red
30
- return
31
- end
32
- rgit.checkout branch
33
- when 'show-root'
34
- rgit.print_roots
26
+ checkout(args)
27
+ when 'show-roots'
28
+ show_roots(args)
35
29
  when 'pull'
36
- rgit.pull
30
+ pull(args)
37
31
  when 'fetch'
38
- rgit.fetch
32
+ fetch(args)
39
33
  when 'status'
40
- rgit.status
34
+ status(args)
41
35
  when 'version'
42
36
  puts "rgit #{VERSION}"
43
37
  else
44
- puts "ERROR: unknown subcommand #{cmd}".red
45
- return
38
+ puts I18n.t('rgit.unknown_subcommand', command: cmd).red
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def rgit_argument_parser
45
+ Trollop::Parser.new do
46
+ banner I18n.t('rgit.banner')
47
+ opt :verbose, I18n.t('rgit.run_verbosely'), short: '-v'
48
+ stop_on SUB_COMMANDS
49
+ end
50
+ end
51
+
52
+ def get_global_options(parser, args)
53
+ Trollop.with_standard_exception_handling parser do
54
+ raise Trollop::HelpNeeded if args.empty?
55
+ parser.parse args
56
+ end
57
+ end
58
+
59
+ def register_options_banner(args, banner_text)
60
+ Trollop.options(args) do
61
+ banner banner_text
46
62
  end
47
63
  end
64
+
65
+ def add_root(args)
66
+ register_options_banner(args, I18n.t('add_root.banner'))
67
+ path = args.size == 1 ? args[0] : Dir.pwd
68
+ @rgit.add_root(path)
69
+ end
70
+
71
+ def remove_root(args)
72
+ register_options_banner(args, I18n.t('remove_root.banner'))
73
+ path = args.size == 1 ? args[0] : Dir.pwd
74
+ @rgit.remove_root(path)
75
+ end
76
+
77
+ def checkout(args)
78
+ register_options_banner(args, I18n.t('checkout.banner'))
79
+ branch = args[0] if args.size == 1
80
+ unless branch
81
+ puts I18n.t('branch.expect_name').red
82
+ return
83
+ end
84
+ @rgit.checkout branch
85
+ end
86
+
87
+ def show_roots(args)
88
+ register_options_banner(args, I18n.t('show_roots.banner'))
89
+ @rgit.print_roots
90
+ end
91
+
92
+ def pull(args)
93
+ register_options_banner(args, I18n.t('pull.banner'))
94
+ @rgit.pull
95
+ end
96
+
97
+ def fetch(args)
98
+ register_options_banner(args, I18n.t('fetch.banner'))
99
+ @rgit.fetch
100
+ end
101
+
102
+ def status(args)
103
+ register_options_banner(args, I18n.t('status.banner'))
104
+ @rgit.status
105
+ end
48
106
  end
49
107
  end
data/lib/rgit/rgit.rb CHANGED
@@ -4,6 +4,7 @@ require 'rgit/cli'
4
4
  require 'optparse'
5
5
  require 'git'
6
6
  require 'colorize'
7
+ require 'i18n'
7
8
  module Rgit
8
9
  class Rgit
9
10
  attr_accessor :verbose
@@ -15,14 +16,14 @@ module Rgit
15
16
 
16
17
  def add_root(path)
17
18
  raise "Not a directory: #{path}" unless File.directory?(path)
18
- puts "Adding root: #{path}"
19
+ puts I18n.t('add_root.adding_root', path: path)
19
20
  @config.add_root path
20
21
  @config.save
21
22
  end
22
23
 
23
24
  def remove_root(path)
24
25
  raise "Not a directory: #{path}" unless File.directory?(path)
25
- puts "Removing root: #{path}"
26
+ puts I18n.t('remove_root.removing_root', path: path)
26
27
  @config.remove_root path
27
28
  @config.save
28
29
  end
@@ -30,7 +31,7 @@ module Rgit
30
31
  def pull(path = Dir.pwd)
31
32
  recursive_cmd(path) do |git|
32
33
  git.remotes.each do |remote|
33
- puts " Pulling remote: #{remote.name}".colorize(:light_cyan)
34
+ puts " #{I18n.t('pull.pulling_remote', name: remote.name)}".colorize(:light_cyan)
34
35
  results = git.pull(remote.name, git.current_branch)
35
36
  puts results.split("\n").map { |l| " #{l}" }.join("\n") if @verbose
36
37
  end
@@ -40,7 +41,7 @@ module Rgit
40
41
  def fetch(path = Dir.pwd)
41
42
  recursive_cmd(path) do |git|
42
43
  git.remotes.each do |remote|
43
- puts " Fetching remote: #{remote.name}".colorize(:light_cyan)
44
+ puts " #{I18n.t('fetch.fetching_remote', name: remote.name)}".colorize(:light_cyan)
44
45
  results = git.fetch(remote.name, all: true)
45
46
  puts results.split("\n").map { |l| " #{l}" }.join("\n") if @verbose
46
47
  end
@@ -49,32 +50,33 @@ module Rgit
49
50
 
50
51
  def checkout(branch, path = Dir.pwd)
51
52
  recursive_cmd(path) do |git|
52
- puts " Checkout branch: #{branch}".colorize(:light_cyan)
53
+ puts " #{I18n.t('checkout.checkout_branch', branch: branch)}".colorize(:light_cyan)
53
54
  git.checkout branch
54
55
  end
55
56
  end
56
57
 
57
58
  def status(path = Dir.pwd)
59
+ puts path
58
60
  recursive_cmd(path) do |git|
59
61
  unless git.status.untracked.empty?
60
- puts " Untracked changes (#{git.current_branch}):".colorize(:light_red)
62
+ puts " #{I18n.t('status.untracked_changes', branch: git.current_branch)}:".colorize(:light_red)
61
63
  git.status.untracked.keys.each { |filename| puts " - #{filename}" }
62
64
  end
63
65
  unless git.status.changed.empty?
64
- puts " Uncommitted changes (#{git.current_branch}):".colorize(:light_magenta)
66
+ puts " #{I18n.t('status.uncommitted_changes', branch: git.current_branch)}:".colorize(:light_magenta)
65
67
  git.status.changed.keys.each { |filename| puts " - #{filename}" }
66
68
  end
67
69
  if git.status.untracked.empty? && git.status.changed.empty?
68
- puts " On branch: #{git.current_branch}".colorize(:green)
70
+ puts " #{I18n.t('status.on_branch', branch: git.current_branch)}".colorize(:green)
69
71
  end
70
72
  end
71
73
  end
72
74
 
73
75
  def print_roots
74
76
  if @config.roots.empty?
75
- puts "No roots have been configured. Run 'rgit --add-root' to add the current directory as a root"
77
+ puts I18n.t('show_roots.no_routes_configured')
76
78
  else
77
- puts 'Roots:'
79
+ puts "#{I18n.t('roots')}:"
78
80
  @config.roots.each do |root|
79
81
  puts " - #{root}"
80
82
  end
@@ -87,11 +89,11 @@ module Rgit
87
89
  parent_path = @config.find_root(path)
88
90
  repositories(parent_path).each do |git|
89
91
  repo_name = git.dir.path.gsub("#{path}/", '')
90
- puts "#{'Repository:'.colorize(:light_blue)} #{repo_name}"
92
+ puts "#{(I18n.t('repository') + ':').colorize(:light_blue)} #{repo_name}"
91
93
  begin
92
94
  yield git
93
95
  rescue Git::GitExecuteError => e
94
- puts ' Failed:'.colorize(:red)
96
+ puts " #{I18n.t('failed')}:".colorize(:red)
95
97
  puts e.message.split("\n").map { |l| " #{l}" }.join("\n").colorize(:red)
96
98
  end
97
99
  end
data/lib/rgit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rgit
2
- VERSION = '1.1'.freeze
2
+ VERSION = '1.2'.freeze
3
3
  end
data/locales/en.yml ADDED
@@ -0,0 +1,115 @@
1
+ en:
2
+ add_root:
3
+ adding_root: 'Adding root: %{path}'
4
+ banner: |
5
+ USAGE:
6
+ rgit add-root [PATH]
7
+
8
+ DESCRIPTION:
9
+ Add a root directory (PATH defaults to working directory if not specified).
10
+
11
+ A 'root' is a parent directory containing many git repositories. By adding a
12
+ directory as a root directory rgit can execute commands on all repositories
13
+ within that root. Regarless of whether you are in a specfic repository or the
14
+ parent folder.
15
+
16
+ OPTIONS:
17
+ branch:
18
+ expect_name: 'ERROR: checkout subcommand expects a branch name'
19
+ checkout:
20
+ banner: |
21
+ USAGE:
22
+ rgit checkout BRANCH
23
+
24
+ DESCRIPTION:
25
+ Checkout the specified branch across all git repositories.
26
+
27
+ OPTIONS:
28
+ checkout_branch: 'Checking branch: %{branch}'
29
+ failed: 'Failed'
30
+ fetch:
31
+ banner: |
32
+ USAGE:
33
+ rgit fetch
34
+
35
+ DESCRIPTION:
36
+ Fetch all repositories within the root (based on working directory).
37
+
38
+ OPTIONS
39
+ fetching_remote: 'Fetching remote: %{name}'
40
+ pull:
41
+ banner: |
42
+ USAGE:
43
+ rgit pull
44
+
45
+ DESCRIPTION:
46
+ Pull all repositories within the root (based on working directory).
47
+
48
+ OPTIONS
49
+ pulling_remote: 'Pulling remote: %{name}'
50
+ remove_root:
51
+ banner: |
52
+ USAGE:
53
+ rgit remove-root [PATH]
54
+
55
+ DESCRIPTION:
56
+ Remove a root directory (PATH defaults to working directory if not specified).
57
+
58
+ OPTIONS
59
+ removing_root: 'Removing root: %{path}'
60
+ rgit:
61
+ banner: |
62
+ rgit is a utility for managing multiple git repositories.
63
+
64
+ USAGE:
65
+ rgit [global options] COMMAND [command options]
66
+
67
+ GLOBAL OPTIONS:
68
+ -v Run verbosely
69
+
70
+ COMMANDS:
71
+ add-root [PATH] Add a root directory (defaults to working directory).
72
+ remove-root [PATH] Remove a root directory (defaults to working directory).
73
+ show-roots Show roots.
74
+ pull Git pull.
75
+ fetch Git fetch.
76
+ checkout BRANCH Git checkout
77
+ status Git status
78
+ -h, --help Show this message
79
+ version Show version
80
+
81
+ ADDITIONAL HELP:
82
+ rgit COMMAND -h
83
+
84
+ OPTIONS:
85
+ run_verbosely: 'Run verbosely'
86
+ unknown_subcommand: 'ERROR: unknown subcommand %{command}'
87
+ repository: 'Repository'
88
+ roots: 'Roots'
89
+ show_roots:
90
+ banner: |
91
+ USAGE:
92
+ rgit show-roots
93
+
94
+ DESCRIPTION:
95
+ Lists the root directories that have been configured.
96
+
97
+ A 'root' is a parent directory containing many git repositories. From within
98
+ a root directory or sub directory of a root it is possible to execute an rgit
99
+ command across all repositories within that root.
100
+
101
+ OPTIONS
102
+ no_routes_configured: "No roots have been configured. Run 'rgit --add-root' to add the current directory as a root"
103
+ status:
104
+ banner: |
105
+ USAGE:
106
+ rgit status
107
+
108
+ DESCRIPTION:
109
+ Show a status summary of all repositories within the root (based on working
110
+ directory).
111
+
112
+ OPTIONS
113
+ untracked_changes: 'Untracked changes: %{branch}'
114
+ uncommitted_changes: 'Uncommitted changes: %{branch}'
115
+ on_branch: 'On branch: %{branch}'
data/r-git.gemspec CHANGED
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency 'trollop', '~> 2.1.2'
31
31
  spec.add_dependency 'git', '~> 1.2.9'
32
32
  spec.add_dependency 'colorize', '~> 0.7.7'
33
+ spec.add_dependency 'i18n', '~> 0.7.0'
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r-git
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Ridgway
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-11 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.7.7
139
+ - !ruby/object:Gem::Dependency
140
+ name: i18n
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.7.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.7.0
139
153
  description: |-
140
154
  Executable gem for managing multiple git repositories in a top level directory. r-git allow
141
155
  you to easily fetch, pull, change branch, etc. across multiple git repositories with a single
@@ -164,6 +178,7 @@ files:
164
178
  - lib/rgit/configuration.rb
165
179
  - lib/rgit/rgit.rb
166
180
  - lib/rgit/version.rb
181
+ - locales/en.yml
167
182
  - r-git.gemspec
168
183
  homepage: https://github.com/jamesridgway/r-git
169
184
  licenses: