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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rubocop.yml +38 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +5 -0
  6. data/.yardopts +1 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +6 -0
  9. data/Gemfile.lock +39 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +196 -0
  12. data/Rakefile +7 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/exe/git-cmd +35 -0
  16. data/git-commander.gemspec +31 -0
  17. data/lib/git_commander.rb +17 -0
  18. data/lib/git_commander/cli.rb +126 -0
  19. data/lib/git_commander/command.rb +168 -0
  20. data/lib/git_commander/command/configurator.rb +26 -0
  21. data/lib/git_commander/command/loaders/file_loader.rb +35 -0
  22. data/lib/git_commander/command/loaders/raw.rb +43 -0
  23. data/lib/git_commander/command/option.rb +43 -0
  24. data/lib/git_commander/command/runner.rb +45 -0
  25. data/lib/git_commander/command_loader_options.rb +34 -0
  26. data/lib/git_commander/loader.rb +28 -0
  27. data/lib/git_commander/loader_result.rb +18 -0
  28. data/lib/git_commander/logger.rb +39 -0
  29. data/lib/git_commander/plugin.rb +50 -0
  30. data/lib/git_commander/plugin/executor.rb +10 -0
  31. data/lib/git_commander/plugin/loader.rb +77 -0
  32. data/lib/git_commander/plugins/git.rb +31 -0
  33. data/lib/git_commander/plugins/github.rb +35 -0
  34. data/lib/git_commander/plugins/prompt.rb +8 -0
  35. data/lib/git_commander/plugins/system.rb +3 -0
  36. data/lib/git_commander/registry.rb +91 -0
  37. data/lib/git_commander/rspec.rb +3 -0
  38. data/lib/git_commander/rspec/plugin_helpers.rb +82 -0
  39. data/lib/git_commander/system.rb +76 -0
  40. data/lib/git_commander/version.rb +5 -0
  41. metadata +159 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7e4e61ccf3751b8e511981eb8335aa65c73e3b4b0932af02bb2a2bbd0046bc08
4
+ data.tar.gz: 0be52ddaf9c2816e931f6af9e63de9f118717de7d2d7db08ec4d9a1d57ffb788
5
+ SHA512:
6
+ metadata.gz: 6f8d75298b07446ec8282f7506a6a93d04a6cd421835bc4eea68295a2cf13fd505a0a3b7b6de1ace831b1e3f031853d82022843770531684f8c2eb791d1132fb
7
+ data.tar.gz: 3d1936108a6079ec03c9c6c8b672dd64e108f5d781479f58bd9766ac68d2fd06291b80f99eb08a958451f1ece847df621a3acbb040f92218faf167647a6f1906
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,38 @@
1
+ Layout/DotPosition:
2
+ EnforcedStyle: trailing
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Style/StringLiterals:
8
+ EnforcedStyle: double_quotes
9
+ ConsistentQuotesInMultiline: true
10
+ Enabled: true
11
+
12
+ Style/StringLiteralsInInterpolation:
13
+ EnforcedStyle: double_quotes
14
+
15
+ Style/LambdaCall:
16
+ Enabled: false
17
+
18
+ Metrics/BlockLength:
19
+ Exclude:
20
+ - ./**/*_spec*.rb
21
+ - ./spec/*_helper*.rb
22
+ - ./spec/support/*
23
+ - ./spec/support/**/*
24
+ - Gemfile
25
+
26
+ Metrics/ModuleLength:
27
+ Exclude:
28
+ - ./**/*_spec*.rb
29
+ - ./spec/support/**/*
30
+
31
+ Metrics/MethodLength:
32
+ Exclude:
33
+ - ./**/*_spec*.rb
34
+ - ./spec/support/**/*
35
+
36
+ Lint/AmbiguousBlockAssociation:
37
+ Exclude:
38
+ - ./**/*_spec.rb
@@ -0,0 +1 @@
1
+ 2.6.5
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1 @@
1
+ --no-private --protected exe/* lib/**/*.rb - CODE_OF_CONDUCT.md README.md LICENSE.txt
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at v@codenamev.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in git-commander.gemspec
6
+ gemspec
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git-commander (0.1.0)
5
+ bundler (~> 2.1, >= 1.10.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (11.1.1)
11
+ diff-lcs (1.3)
12
+ rake (12.3.3)
13
+ rdoc (6.2.1)
14
+ rspec (3.9.0)
15
+ rspec-core (~> 3.9.0)
16
+ rspec-expectations (~> 3.9.0)
17
+ rspec-mocks (~> 3.9.0)
18
+ rspec-core (3.9.1)
19
+ rspec-support (~> 3.9.1)
20
+ rspec-expectations (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-mocks (3.9.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-support (3.9.2)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ byebug (~> 11)
33
+ git-commander!
34
+ rake (~> 12.3)
35
+ rdoc (~> 6.2)
36
+ rspec (< 4.0)
37
+
38
+ BUNDLED WITH
39
+ 2.1.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Valentino Stoll
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,196 @@
1
+ # git-commander
2
+
3
+ Make your own git commands.
4
+
5
+ Installation
6
+ ============
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'git-commander'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install git-commander
21
+
22
+ Usage
23
+ =====
24
+
25
+ All commands you register can be run using `git cmd ...`.
26
+
27
+ Registering a new command is as easy as creating a new `Workflow` file in your git-root's directory (or organize them in a `.git-commands` directory).
28
+ Example:
29
+
30
+ ```ruby
31
+ # ~/git-root/.git-commands/current.rb
32
+
33
+ plugin :system
34
+
35
+ command :current do |cmd|
36
+ cmd.summary "Outputs all commits not on the base branch"
37
+ cmd.argument :base_branch, default: "master"
38
+
39
+ cmd.on_run do |options|
40
+ current_branch = system.run "git rev-parse --abbrev-ref HEAD"
41
+ system.run "git log #{options[:base_branch]}..#{current_branch} --format=\"%C(auto)%h %s %C(#999999)%ar\" --color"
42
+ end
43
+ end
44
+ ```
45
+
46
+ In the above example, we:
47
+
48
+ 1. Use the native `system` plugin. This gives us access to an instance of [System](/docs/GitCommander/System) inside of our `on_run` block.
49
+ 2. Creates a new `git cmd current :base_branch` command and runs everything in the `on_run` block when we execute it (passing the `:base_branch` in the `options`)
50
+
51
+ `cmd` can configure multiple `argument`, `flag`, `switch` options, and a `default: 'some value'` can be set for any.
52
+ A long-form `description` can also be set for your commands for use in the command's help text: `git cmd help current`.
53
+
54
+ You can define multiple commands in a single file if you wish, but it is recommended to keep commands contained to their own file.
55
+
56
+ Gem usage
57
+ =========
58
+
59
+ Command declaration files can include their own inline gems:
60
+
61
+ ```ruby
62
+ gemfile do
63
+ source "https://rubygems.org"
64
+ gem "octokit"
65
+ end
66
+ ```
67
+
68
+ Plugins
69
+ =======
70
+
71
+ Git-commander is built with the intention of being extended. To make things
72
+ flexible, there is a plugin architecture that allows you to define new top-level
73
+ methods that can be available inside of your command's `on_run` blocks.
74
+
75
+ As a simple example, if you wanted access to a `github` method to perform API calls, you can use the [octokit gem](https://github.com/octokit/octokit.rb) to do this:
76
+
77
+ ```ruby
78
+ # .git-commands/plugins/github.rb
79
+ gemfile do
80
+ source "https://rubygems.org"
81
+ gem "octokit"
82
+ end
83
+
84
+ Octokit::Client.new
85
+ ```
86
+
87
+ Then in a new command, use the new `github` plugin:
88
+
89
+ ```ruby
90
+ plugin :github
91
+
92
+ command :prs do |cmd|
93
+ cmd.summary "Lists all open GitHub PullRequests for the git-commander repo"
94
+
95
+ cmd.on_run do |cmd|
96
+ github.pull_requests("codenamev/git-commander", state: "open").each do |pr|
97
+ say "@#{pr.user.login} #{pr.title} – #{pr.html_url}"
98
+ end
99
+ end
100
+ end
101
+ ```
102
+
103
+ ### Anatomy of a plugin
104
+
105
+ 1. [Name of the plugin](#name-of-the-plugin)
106
+ 2. [Gem dependencies](#gem-dependencies) (via `gemfile` block)
107
+ 3. [Plugin dependencies](#plugin-dependencies)
108
+ 4. [Plugin-specific commands](#plugin-specific-commands)
109
+ 5. [The plugin instance](#the-plugin-instance)
110
+
111
+ Name of the plugin
112
+ ------------------
113
+
114
+ As mentioned in the simple example above, the filename of the plugin defines the keyword that will be available within the `on_run` blocks of your commands. Plugins must be added to your `.git-commands/plugins` directory, and the file extension must be `.rb`. Whatever you name the file becomes the name used internally to reference it. So if you name your plugin `some-awesome-plugin.rb`, you will have to reference it as `plugin 'some-awesome-plugin'`.
115
+
116
+ Gem dependencies
117
+ ----------------
118
+
119
+ Just like commands, you can include third-party gems using [Bundler's inline helpers](https://github.com/rubygems/bundler/blob/master/lib/bundler/inline.rb).
120
+
121
+ Plugin dependencies
122
+ -------------------
123
+
124
+ Also the same as with commands, plugins can also define other plugins as dependencies. We include the following plugins natively:
125
+
126
+ - [git](https://github.com/codenamev/git-commander/blob/master/lib/git_commander/plugins/git.rb)
127
+ - [github](https://github.com/codenamev/git-commander/blob/master/lib/git_commander/plugins/github.rb)
128
+ - [prompt](https://github.com/codenamev/git-commander/blob/master/lib/git_commander/plugins/prompt.rb)
129
+ - [system](https://github.com/codenamev/git-commander/blob/master/lib/git_commander/plugins/system.rb)
130
+
131
+ Plugin-specific commands
132
+ ------------------------
133
+
134
+ Plugins can also define their own commands. These commands will be namespaced to the name of the plugin. So the following plugin would allow you to run `git cmd github:setup`.
135
+
136
+ ```ruby
137
+ gemfile do
138
+ source "https://rubygems.org"
139
+ gem "octokit"
140
+ end
141
+
142
+ plugin :prompt
143
+
144
+ command :setup do |cmd|
145
+ cmd.summary "Connects to GitHub, creates an access token, and stores it in the git-cmd section of your git config"
146
+
147
+ cmd.on_run do
148
+ gh_user = prompt.ask("Please enter your GitHub username", required: true)
149
+ gh_password = promt.mask("Please enter your GitHub password (this is NOT stored): ", required: true)
150
+
151
+ github.login = gh_user
152
+ github.password = gh_password
153
+
154
+ # Check for 2-factor requirements
155
+ begin
156
+ client.user
157
+ rescue Octokit::Unauthorized
158
+ github.user(
159
+ gh_user,
160
+ headers: { "X-GitHub-OTP" => prompt.ask("Please enter your two-factor authentication code") }
161
+ )
162
+ end
163
+
164
+ say "GitHub account successfully setup!"
165
+ end
166
+ end
167
+
168
+ Octokit::Client.new
169
+ ```
170
+
171
+ The plugin instance
172
+ -------------------
173
+
174
+ When plugins are loaded, their content is evaluated in the context of the Plugin::Loader class. Whatever the file returns (the last line evaluated) is stored as the plugin's instance. In this way, whenever you reference the plugin from within a command's `on_run`, you are referencing the same instance that was returned from evaluating the plugin's file.
175
+
176
+ Development
177
+ ===========
178
+
179
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
180
+
181
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
182
+
183
+ Contributing
184
+ ============
185
+
186
+ [Bug reports](https://github.com/codenamev/git-commander/issues/new) and [pull requests](https://github.com/codenamev/git-commander/pulls) are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
187
+
188
+ License
189
+ =======
190
+
191
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
192
+
193
+ Code of Conduct
194
+ ===============
195
+
196
+ Everyone interacting in the GitCommander project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/codenamev/git-commander/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "git_commander"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift "#{__dir__}/../lib"
5
+
6
+ require "rubygems"
7
+ require "git_commander"
8
+ require "git_commander/cli"
9
+
10
+ runner = GitCommander::CLI.new
11
+
12
+ plugin_files = Dir[
13
+ File.join(Dir.pwd, ".git-commands", "plugins", "*.rb")
14
+ ]
15
+ command_files = Dir[
16
+ File.join(Dir.pwd, "Workflow"),
17
+ File.join(Dir.pwd, ".git-commands", "*.rb")
18
+ ]
19
+
20
+ command_files.each do |filename|
21
+ loader = runner.registry.load GitCommander::Command::Loaders::FileLoader, filename if File.exist?(filename)
22
+ unless loader.success?
23
+ GitCommander.logger.warn "Unable to load command from: #{filename}\n\tErrors: #{loader.errors.inspect}"
24
+ end
25
+ end
26
+
27
+ plugin_files.each do |filename|
28
+ loader = runner.registry.load GitCommander::Plugin::Loader, filename if File.exist?(filename)
29
+ unless loader.success?
30
+ GitCommander.logger.warn "Unable to load plugin from: #{filename}\n\tErrors: #{loader.errors.inspect}"
31
+ GitCommander.logger.debug "\n\tBacktrace: #{loader.errors.map(&:backtrace)}"
32
+ end
33
+ end
34
+
35
+ runner.run