git-commander 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +38 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/.yardopts +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +39 -0
- data/LICENSE.txt +21 -0
- data/README.md +196 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/git-cmd +35 -0
- data/git-commander.gemspec +31 -0
- data/lib/git_commander.rb +17 -0
- data/lib/git_commander/cli.rb +126 -0
- data/lib/git_commander/command.rb +168 -0
- data/lib/git_commander/command/configurator.rb +26 -0
- data/lib/git_commander/command/loaders/file_loader.rb +35 -0
- data/lib/git_commander/command/loaders/raw.rb +43 -0
- data/lib/git_commander/command/option.rb +43 -0
- data/lib/git_commander/command/runner.rb +45 -0
- data/lib/git_commander/command_loader_options.rb +34 -0
- data/lib/git_commander/loader.rb +28 -0
- data/lib/git_commander/loader_result.rb +18 -0
- data/lib/git_commander/logger.rb +39 -0
- data/lib/git_commander/plugin.rb +50 -0
- data/lib/git_commander/plugin/executor.rb +10 -0
- data/lib/git_commander/plugin/loader.rb +77 -0
- data/lib/git_commander/plugins/git.rb +31 -0
- data/lib/git_commander/plugins/github.rb +35 -0
- data/lib/git_commander/plugins/prompt.rb +8 -0
- data/lib/git_commander/plugins/system.rb +3 -0
- data/lib/git_commander/registry.rb +91 -0
- data/lib/git_commander/rspec.rb +3 -0
- data/lib/git_commander/rspec/plugin_helpers.rb +82 -0
- data/lib/git_commander/system.rb +76 -0
- data/lib/git_commander/version.rb +5 -0
- metadata +159 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rspec/mocks/matchers/receive"
|
4
|
+
require "rspec/mocks/any_instance"
|
5
|
+
require "rspec/support/differ"
|
6
|
+
|
7
|
+
module GitCommander
|
8
|
+
module RSpec
|
9
|
+
# Contains helper methods and matchers for testing git-commander plugins
|
10
|
+
module PluginHelpers
|
11
|
+
# nodoc
|
12
|
+
class MockGemfile
|
13
|
+
DEFAULT_GEM_SOURCE = "https://rubygems.org"
|
14
|
+
|
15
|
+
attr_reader :gems, :options
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@gems = {}
|
19
|
+
@source = DEFAULT_GEM_SOURCE
|
20
|
+
end
|
21
|
+
|
22
|
+
def gem(name, *options)
|
23
|
+
@gems[name] = options || []
|
24
|
+
end
|
25
|
+
|
26
|
+
def source(value = nil)
|
27
|
+
return "source: '#{@source}'" if value.nil?
|
28
|
+
|
29
|
+
@source = value
|
30
|
+
end
|
31
|
+
|
32
|
+
def gemfile_lines
|
33
|
+
[
|
34
|
+
source,
|
35
|
+
*@gems.map { |name, options| gem_definition(name, *options) }
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
def gem_definition(name, *options)
|
40
|
+
["gem '#{name}'", *Array(options).map { |o| gem_option_to_s(o) }].join(", ")
|
41
|
+
end
|
42
|
+
|
43
|
+
def gem_option_to_s(option)
|
44
|
+
return "" if option.to_s.empty?
|
45
|
+
|
46
|
+
case option
|
47
|
+
when Hash
|
48
|
+
option.map { |k, v| "#{k}: '#{v}'" }
|
49
|
+
else
|
50
|
+
"'#{option}'"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def stub_inline_gemfile
|
56
|
+
mock_gemfile = MockGemfile.new
|
57
|
+
allow_any_instance_of(GitCommander::Plugin::Loader).to receive(:gemfile) do |*args, &block|
|
58
|
+
mock_gemfile.instance_eval(&block)
|
59
|
+
end
|
60
|
+
mock_gemfile
|
61
|
+
end
|
62
|
+
|
63
|
+
::RSpec::Matchers.define :have_defined_gems do |gemfile_lines|
|
64
|
+
gemfile_lines.map! { |l| l.gsub(/"/, "'") }
|
65
|
+
gemfile_lines.prepend(MockGemfile.new.source) if gemfile_lines.none? { |line| line.start_with?("source:") }
|
66
|
+
|
67
|
+
match do |block|
|
68
|
+
mock_gemfile = stub_inline_gemfile unless GitCommander::Plugin::Loader.new(nil).is_a?(MockGemfile)
|
69
|
+
|
70
|
+
block.call
|
71
|
+
|
72
|
+
@actual = mock_gemfile.gemfile_lines
|
73
|
+
|
74
|
+
values_match? gemfile_lines, @actual
|
75
|
+
end
|
76
|
+
|
77
|
+
diffable
|
78
|
+
supports_block_expectations
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "singleton"
|
4
|
+
require "open3"
|
5
|
+
|
6
|
+
module GitCommander
|
7
|
+
# @abstract A wrapper for system calls
|
8
|
+
class System
|
9
|
+
DEFAULT_RUN_OPTIONS = {
|
10
|
+
silent: false
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
# @abstract Wraps a system command with logging, stderr, and stdout capture
|
14
|
+
class Command
|
15
|
+
attr_accessor :output, :error, :status
|
16
|
+
attr_reader :name, :options, :command_with_arguments
|
17
|
+
def initialize(command_with_arguments, options = {})
|
18
|
+
@command_with_arguments = command_with_arguments
|
19
|
+
@name = command_with_arguments.split(/\w/i).first
|
20
|
+
@options = DEFAULT_RUN_OPTIONS.merge(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
log_command_initiated
|
25
|
+
@output, @error, @status = Open3.capture3(command_with_arguments)
|
26
|
+
log_command_completed
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def log_command_initiated
|
32
|
+
GitCommander.logger.debug <<~COMMAND_LOG
|
33
|
+
[system] Running '#{command_with_arguments}' with options #{options.inspect} ...
|
34
|
+
COMMAND_LOG
|
35
|
+
end
|
36
|
+
|
37
|
+
def log_command_completed
|
38
|
+
GitCommander.logger.debug <<~COMMAND_LOG
|
39
|
+
[system] Ran '#{command_with_arguments}' with options #{options.inspect}.
|
40
|
+
\tStatus: #{status}
|
41
|
+
\tOutput: #{output.inspect}
|
42
|
+
\tError: #{error.inspect}
|
43
|
+
COMMAND_LOG
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class RunError < StandardError; end
|
48
|
+
|
49
|
+
include Singleton
|
50
|
+
|
51
|
+
# Runs a system command
|
52
|
+
# @param [String] command_with_arguments the command string (with args, flags and switches) to run
|
53
|
+
# @param [Hash] options the options to run the command with
|
54
|
+
# @option options [Boolean] :silent Supress the output of the command
|
55
|
+
# @option options [Boolean] :blocking Supress errors running the command
|
56
|
+
def self.run(command_with_arguments, options = {})
|
57
|
+
command = Command.new(command_with_arguments, options)
|
58
|
+
|
59
|
+
command.run
|
60
|
+
|
61
|
+
unless command.status.success? || command.options[:blocking] == false
|
62
|
+
raise RunError, "\"#{command.error}\" \"#{command.name}\" failed to run."
|
63
|
+
end
|
64
|
+
|
65
|
+
puts command.output if command.options[:silent] == false
|
66
|
+
command.output.strip
|
67
|
+
end
|
68
|
+
|
69
|
+
# Appends to the output stream
|
70
|
+
# @param [String] new_output the string to add to the output stream
|
71
|
+
def self.say(new_output)
|
72
|
+
GitCommander.logger.info "[System#say] #{new_output}"
|
73
|
+
puts new_output
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-commander
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Valentino Stoll
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "<"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "<"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.1'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.10.0
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.1'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.10.0
|
89
|
+
description: Build custom flexible git workflows with Ruby!
|
90
|
+
email:
|
91
|
+
- v@codenamev.com
|
92
|
+
executables:
|
93
|
+
- git-cmd
|
94
|
+
extensions: []
|
95
|
+
extra_rdoc_files: []
|
96
|
+
files:
|
97
|
+
- ".gitignore"
|
98
|
+
- ".rubocop.yml"
|
99
|
+
- ".ruby-version"
|
100
|
+
- ".travis.yml"
|
101
|
+
- ".yardopts"
|
102
|
+
- CODE_OF_CONDUCT.md
|
103
|
+
- Gemfile
|
104
|
+
- Gemfile.lock
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- bin/console
|
109
|
+
- bin/setup
|
110
|
+
- exe/git-cmd
|
111
|
+
- git-commander.gemspec
|
112
|
+
- lib/git_commander.rb
|
113
|
+
- lib/git_commander/cli.rb
|
114
|
+
- lib/git_commander/command.rb
|
115
|
+
- lib/git_commander/command/configurator.rb
|
116
|
+
- lib/git_commander/command/loaders/file_loader.rb
|
117
|
+
- lib/git_commander/command/loaders/raw.rb
|
118
|
+
- lib/git_commander/command/option.rb
|
119
|
+
- lib/git_commander/command/runner.rb
|
120
|
+
- lib/git_commander/command_loader_options.rb
|
121
|
+
- lib/git_commander/loader.rb
|
122
|
+
- lib/git_commander/loader_result.rb
|
123
|
+
- lib/git_commander/logger.rb
|
124
|
+
- lib/git_commander/plugin.rb
|
125
|
+
- lib/git_commander/plugin/executor.rb
|
126
|
+
- lib/git_commander/plugin/loader.rb
|
127
|
+
- lib/git_commander/plugins/git.rb
|
128
|
+
- lib/git_commander/plugins/github.rb
|
129
|
+
- lib/git_commander/plugins/prompt.rb
|
130
|
+
- lib/git_commander/plugins/system.rb
|
131
|
+
- lib/git_commander/registry.rb
|
132
|
+
- lib/git_commander/rspec.rb
|
133
|
+
- lib/git_commander/rspec/plugin_helpers.rb
|
134
|
+
- lib/git_commander/system.rb
|
135
|
+
- lib/git_commander/version.rb
|
136
|
+
homepage: https://github.com/codenamev/git-commander
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubygems_version: 3.1.2
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: Make your own git commands
|
159
|
+
test_files: []
|