rlt 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d0cb19ba69b703d07058564907203ab6bbc716bab2654fe5f9c000f3bb24d832
4
+ data.tar.gz: 639736fda1fe706d93af147cf5c714ad6cdf01a2501721e86643dd15842ed49c
5
+ SHA512:
6
+ metadata.gz: a54919542cc2a188907e861a6a78650908be973e48889da506dce0eb27e3e5d9f6f3e8025f4a717ae01503c8d219d5e534e2586749769801b38f1593e5f15c4a
7
+ data.tar.gz: 483957a5f2a7f4a9b17488de76a954f78a8ff4d747ffac538e2ba61131c472bba282a4e855ba5de35b7d400f3c48943d710b8a0108b5f1bdf48ea190d27897f5
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .idea/
2
+
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rlt.sample.yml ADDED
@@ -0,0 +1,24 @@
1
+ command:
2
+ switch:
3
+ branch_name_template: JIRA-<%= branch_name %>
4
+ cmt:
5
+ subject_template: >
6
+ <%=
7
+ if branch_name.start_with?('JIRA-')
8
+ "[#{branch_name}] #{subject}"
9
+ else
10
+ subject
11
+ end
12
+ %>
13
+ body_template: >
14
+ <%=
15
+ if branch_name.start_with?('JIRA-')
16
+ "http://myjira.com/#{branch_name}\n\n#{body}"
17
+ else
18
+ body
19
+ end
20
+ %>
21
+ alias:
22
+ br: branch
23
+ sw: switch
24
+ l: log --oneline
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+ Documentation:
2
+ Enabled: false
3
+ Metrics/LineLength:
4
+ Max: 100
5
+ Metrics/MethodLength:
6
+ Max: 5
7
+ AllCops:
8
+ Exclude:
9
+ - 'lib/rlt/base_command.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.0
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.1
@@ -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 paul@valuepotion.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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in rlt.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rlt (0.1.1)
5
+ pastel (~> 0.7.2)
6
+ tty-command (~> 0.8.0)
7
+ tty-prompt (~> 0.16.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.0)
13
+ diff-lcs (1.3)
14
+ equatable (0.5.0)
15
+ hitimes (1.2.6)
16
+ necromancer (0.4.0)
17
+ parallel (1.12.1)
18
+ parser (2.5.1.0)
19
+ ast (~> 2.4.0)
20
+ pastel (0.7.2)
21
+ equatable (~> 0.5.0)
22
+ tty-color (~> 0.4.0)
23
+ powerpack (0.1.1)
24
+ rainbow (3.0.0)
25
+ rake (10.5.0)
26
+ rspec (3.7.0)
27
+ rspec-core (~> 3.7.0)
28
+ rspec-expectations (~> 3.7.0)
29
+ rspec-mocks (~> 3.7.0)
30
+ rspec-core (3.7.1)
31
+ rspec-support (~> 3.7.0)
32
+ rspec-expectations (3.7.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-mocks (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-support (3.7.1)
39
+ rubocop (0.55.0)
40
+ parallel (~> 1.10)
41
+ parser (>= 2.5)
42
+ powerpack (~> 0.1)
43
+ rainbow (>= 2.2.2, < 4.0)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (~> 1.0, >= 1.0.1)
46
+ ruby-progressbar (1.9.0)
47
+ timers (4.1.2)
48
+ hitimes
49
+ tty-color (0.4.2)
50
+ tty-command (0.8.0)
51
+ pastel (~> 0.7.0)
52
+ tty-cursor (0.5.0)
53
+ tty-prompt (0.16.1)
54
+ necromancer (~> 0.4.0)
55
+ pastel (~> 0.7.0)
56
+ timers (~> 4.0)
57
+ tty-cursor (~> 0.5.0)
58
+ tty-reader (~> 0.3.0)
59
+ tty-reader (0.3.0)
60
+ tty-cursor (~> 0.5.0)
61
+ tty-screen (~> 0.6.4)
62
+ wisper (~> 2.0.0)
63
+ tty-screen (0.6.4)
64
+ unicode-display_width (1.3.2)
65
+ wisper (2.0.0)
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ bundler (~> 1.16)
72
+ rake (~> 10.0)
73
+ rlt!
74
+ rspec (~> 3.0)
75
+ rubocop
76
+
77
+ BUNDLED WITH
78
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Paul Lee
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.
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # Rlt
2
+
3
+ rlt is a git wrapper with convenient methods included.
4
+
5
+ ## Commands
6
+
7
+ ### cmt
8
+ ```bash
9
+ $ rlt cmt
10
+ Commiting to 'master'
11
+
12
+ Subject: Fix a bug where user cannot login
13
+ Body:
14
+ > There was a problem at ......
15
+ >
16
+ ```
17
+
18
+ If there's nothing to put as body, you can just hit enter to skip it.
19
+
20
+ ### switch
21
+ ```bash
22
+ $ rlt switch <branch_name>
23
+ ```
24
+
25
+ This will switch to `<branch_name>`. If the branch does not exist, then it will create it.
26
+
27
+ ## Configuration
28
+
29
+ The great power in rlt comes from configuration, using ERB syntax in YAML.
30
+
31
+ ```yaml
32
+ command:
33
+ switch:
34
+ branch_name_template: feature-<%= branch_name %>
35
+ cmt:
36
+ subject_template: My prefix <%= subject %>
37
+ body_template: <%= body %> http://...
38
+ alias:
39
+ br: branch
40
+ sw: switch
41
+ l: log --oneline
42
+ ```
43
+
44
+ ### switch
45
+ When you type `rlt switch login`, then it will automatically switch to a branch named `feature-login`.
46
+ * Variable available for `branch_name_template` is `branch_name`.
47
+
48
+ ### cmt
49
+ When you `cmt` with subject 'Hello' and body 'World', then the commit message will be:
50
+
51
+ ```
52
+ My prefix Hello
53
+
54
+ World http://...
55
+ ```
56
+
57
+ * Variables available for `subject_template` are `branch_name` and `subject`.
58
+ * Variables available for `body_template` are `branch_name` and `body`.
59
+
60
+ ### alias
61
+ You can define alias as you want.
62
+
63
+ ### Advanced
64
+ You can utilize this configuration as you want. Just for your information, you can do things like this:
65
+
66
+ ```yaml
67
+ command:
68
+ switch:
69
+ branch_name_template: JIRA-<%= branch_name %>
70
+ cmt:
71
+ subject_template: >
72
+ <%=
73
+ if branch_name.start_with?('JIRA-')
74
+ "[#{branch_name}] #{subject}"
75
+ else
76
+ subject
77
+ end
78
+ %>
79
+ body_template: >
80
+ <%=
81
+ if branch_name.start_with?('JIRA-')
82
+ "http://myjira.com/#{branch_name}\n\n#{body}"
83
+ else
84
+ body
85
+ end
86
+ %>
87
+ alias:
88
+ br: branch
89
+ sw: switch
90
+ l: log --oneline
91
+ ```
92
+
93
+ If you do `rlt switch 123`, then you'll be in `JIRA-123` branch.
94
+
95
+ As long as you're in that branch, when you `cmt` with subject 'Hello' and body 'World', then the commit message will be:
96
+
97
+ ```
98
+ [JIRA-123] Hello
99
+
100
+ http://myjira.com/JIRA-123
101
+
102
+ World
103
+ ```
104
+
105
+ This helps you construct commit message with a convention of yours.
106
+
107
+ ## Installation
108
+
109
+ $ gem install rlt
110
+
111
+ (not ready yet for brew)
112
+
113
+ rlt wraps all the native commands of git. So you can make the alias like the following:
114
+
115
+ $ echo "alias git='rlt'" >> ~/.bash_profile && source ~/.bash_profile
116
+
117
+ ## TODO
118
+
119
+ * `undo` : Uncommit latest commit
120
+ * `close` : Merge this branch into master(or whatever you configure) and delete this branch
121
+ * any suggestion?
122
+
123
+ ## Development
124
+
125
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
126
+
127
+ 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).
128
+
129
+ ## Contributing
130
+
131
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eunjae-lee/rlt. 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.
132
+
133
+ ## License
134
+
135
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
136
+
137
+ ## Code of Conduct
138
+
139
+ Everyone interacting in the Rlt project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/eunjae-lee/rlt/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rlt'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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
data/exe/rlt ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
6
+
7
+ require 'rlt'
8
+
9
+ Rlt.run(ARGV)
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rlt
4
+ class BaseCommand
5
+ def self.run(config, *arguments)
6
+ raise 'implement me'
7
+ end
8
+
9
+ def self.print_help(*arguments)
10
+ raise 'implement me'
11
+ end
12
+
13
+ def self.valid_parameters?(*arguments)
14
+ raise 'implement me'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rlt
4
+ module CommandRunner
5
+ def run(argv)
6
+ command = argv[0]
7
+ arguments = argv[1..-1]
8
+ info = Rlt::CommandsMap.get(command)
9
+ return print_help if info.nil? || info[:class].nil?
10
+ validate_and_run_command(command, info[:default_args] + arguments, info[:class])
11
+ end
12
+
13
+ def print_help
14
+ puts 'Available commands:'
15
+ Rlt::CommandsMap.commands.each do |command|
16
+ desc = Rlt::CommandsMap.desc(command)
17
+ puts " #{command}#{spaces(command)} #{desc}"
18
+ end
19
+ end
20
+
21
+ def spaces(command)
22
+ size = max_command_length - command.size
23
+ ' ' * size
24
+ end
25
+
26
+ def max_command_length
27
+ @max_command_length ||= Rlt::CommandsMap.commands.map(&:size).max
28
+ end
29
+
30
+ def validate_and_run_command(command, arguments, command_class)
31
+ valid = command_class.valid_parameters?(*arguments)
32
+ return command_class.print_help(*arguments) unless valid
33
+ config = Rlt.config('command', command)
34
+ command_class.run(config, *arguments)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+ require 'pastel'
5
+ require 'tty-prompt'
6
+ require 'tmpdir'
7
+
8
+ module Rlt
9
+ module Commands
10
+ class CmtCommand < BaseCommand
11
+ CONF_SUBJECT_TEMPLATE = 'subject_template'.freeze
12
+ CONF_BODY_TEMPLATE = 'body_template'.freeze
13
+
14
+ def self.run(config, *arguments)
15
+ branch_name = acquire_branch_name
16
+ puts "Commiting to '#{Pastel.new.green(branch_name)}'\n\n"
17
+ (subject, body) = subject_and_body(config, branch_name)
18
+ add_all if arguments[0] == '-a'
19
+ commit(subject, body)
20
+ end
21
+
22
+ def self.add_all
23
+ Shell.new.run 'git', 'add', '.'
24
+ end
25
+
26
+ def self.subject_and_body(config, branch_name)
27
+ subject = adjust_subject_template(ask_subject, config, branch_name)
28
+ body = adjust_body_template(ask_body, config, branch_name)
29
+ [subject, body]
30
+ end
31
+
32
+ def self.commit(subject, body)
33
+ commit_msg_file_path = "#{Dir.tmpdir}/.rlt.commit.msg.#{short_random_string}"
34
+ File.write(commit_msg_file_path, "#{subject}\n\n#{body}")
35
+ Shell.new.run 'git', 'commit', '-F', commit_msg_file_path
36
+ File.delete(commit_msg_file_path)
37
+ end
38
+
39
+ def self.short_random_string
40
+ (0...4).map { rand(65..90).chr }.join
41
+ end
42
+
43
+ def self.ask_subject
44
+ prompt = TTY::Prompt.new
45
+ prompt.ask('Subject:', active_color: :cyan) do |q|
46
+ q.required true
47
+ q.modify :capitalize
48
+ end
49
+ end
50
+
51
+ def self.ask_body
52
+ puts 'Body: ' + Pastel.new.magenta('(Insert empty line to finish)')
53
+ lines = ask_multiline_until_done('>', :cyan)
54
+ lines.join("\n")
55
+ end
56
+
57
+ # rubocop:disable Metrics/MethodLength
58
+ def self.ask_multiline_until_done(message, active_color)
59
+ lines = []
60
+ loop do
61
+ line = TTY::Prompt.new.ask(message, active_color: active_color)
62
+ break if line.nil?
63
+ lines << line
64
+ end
65
+ lines
66
+ end
67
+ # rubocop:enable Metrics/MethodLength
68
+
69
+ def self.adjust_subject_template(subject, config, branch_name)
70
+ template = config[CONF_SUBJECT_TEMPLATE]
71
+ return subject if config.nil? || template.nil?
72
+ ERB.new(template).result binding
73
+ end
74
+
75
+ def self.adjust_body_template(body, config, branch_name)
76
+ template = config[CONF_BODY_TEMPLATE]
77
+ return body if config.nil? || template.nil?
78
+ ERB.new(template).result binding
79
+ end
80
+
81
+ def self.acquire_branch_name
82
+ `git rev-parse --abbrev-ref HEAD`.strip
83
+ end
84
+
85
+ def self.print_help(*_arguments)
86
+ puts 'USAGE:'
87
+ puts ' 1. rlt commit # Almost same as `git commit`. You do not need `-m` parameter here.'
88
+ puts ''
89
+ puts ' 2. rlt commit -a # This performs `git add .` before committing.'
90
+ end
91
+
92
+ def self.valid_parameters?(*arguments)
93
+ arguments.empty? || (arguments.size == 1 && arguments[0] == '-a')
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module Rlt
6
+ module Commands
7
+ class SwitchCommand < BaseCommand
8
+ CONF_BRANCH_NAME_TEMPLATE = 'branch_name_template'.freeze
9
+
10
+ def self.run(config, *arguments)
11
+ branch_name = change_branch_name(config, arguments[0])
12
+ switch(branch_name)
13
+ end
14
+
15
+ def self.change_branch_name(config, branch_name)
16
+ branch_name_template = config[CONF_BRANCH_NAME_TEMPLATE]
17
+ return branch_name if branch_name_template.nil?
18
+ ERB.new(branch_name_template).result binding
19
+ end
20
+
21
+ def self.switch(branch_name)
22
+ create_and_checkout(branch_name) if checkout(branch_name).failure?
23
+ end
24
+
25
+ def self.checkout(branch_name)
26
+ result = shell.run_safely 'git', 'checkout', branch_name
27
+ Logger.info "Switched to '#{branch_name}'." unless result.failure?
28
+ result
29
+ end
30
+
31
+ def self.create_and_checkout(branch_name)
32
+ shell.run 'git', 'checkout', '-b', branch_name
33
+ Logger.info "Created & Switched to '#{branch_name}'."
34
+ end
35
+
36
+ def self.print_help(*_arguments)
37
+ puts 'USAGE:'
38
+ puts ' rlt switch <branch_name>'
39
+ puts ''
40
+ puts ' This command switches to <branch_name>. It creates the branch if it does not exist.'
41
+ end
42
+
43
+ def self.valid_parameters?(*arguments)
44
+ arguments.size == 1
45
+ end
46
+
47
+ def self.shell
48
+ Shell.new(no_output: true)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rlt
4
+ class CommandsMap
5
+ def self.add(command_name, command_desc, command_class, default_args = [])
6
+ map[command_name] = {
7
+ class: command_class,
8
+ desc: command_desc,
9
+ default_args: default_args
10
+ }
11
+ end
12
+
13
+ def self.add_alias(command_name, args)
14
+ dest_command_name = args.first
15
+ default_args = args[1..-1]
16
+ dest_command_class = map[dest_command_name][:class]
17
+ desc = "Alias for \"#{args.join(' ')}\""
18
+ add(command_name, desc, dest_command_class, default_args)
19
+ end
20
+
21
+ def self.get(command_name)
22
+ map[command_name]
23
+ end
24
+
25
+ def self.desc(command_name)
26
+ get(command_name)[:desc]
27
+ end
28
+
29
+ def self.commands
30
+ map.keys
31
+ end
32
+
33
+ def self.map
34
+ (@map ||= {})
35
+ end
36
+ end
37
+ end
data/lib/rlt/config.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Rlt
6
+ module Config
7
+ def config(category, command)
8
+ category_config(category)[command]
9
+ rescue NoMethodError
10
+ {}
11
+ end
12
+
13
+ def config_keys(category)
14
+ category_config(category).keys
15
+ rescue NoMethodError
16
+ []
17
+ end
18
+
19
+ def category_config(category)
20
+ (@config ||= load_config)[category]
21
+ end
22
+
23
+ def load_config
24
+ YAML.load_file(file_path)
25
+ rescue Errno::ENOENT
26
+ {}
27
+ end
28
+
29
+ def file_path
30
+ if Rlt.debug
31
+ "#{Dir.pwd}/.rlt.sample.yml"
32
+ else
33
+ "#{Dir.pwd}/.rlt.yml"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rlt
4
+ module Commands
5
+ class GitNativeCommandBuilder
6
+ # rubocop:disable Metrics/MethodLength
7
+ def self.build(command)
8
+ Class.new do
9
+ define_singleton_method :run do |_config, *arguments|
10
+ Shell.new.run_safely 'git', command, *arguments
11
+ end
12
+
13
+ define_singleton_method :print_help do |*_arguments|
14
+ # nothing to do
15
+ end
16
+
17
+ define_singleton_method :valid_parameters? do |*_arguments|
18
+ true
19
+ end
20
+ end
21
+ end
22
+ # rubocop:enable Metrics/MethodLength
23
+ end
24
+ end
25
+ end
data/lib/rlt/logger.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pastel'
4
+
5
+ module Rlt
6
+ class Logger
7
+ def self.verbose(msg)
8
+ puts Pastel.new.white(msg)
9
+ end
10
+
11
+ def self.info(msg)
12
+ puts Pastel.new.cyan(msg)
13
+ end
14
+
15
+ def self.warn(msg)
16
+ puts Pastel.new.yellow(msg)
17
+ end
18
+
19
+ def self.error(msg)
20
+ puts Pastel.new.red(msg)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rlt/commands_map'
4
+
5
+ module Rlt
6
+ class RegisterAliases
7
+ def self.register
8
+ Rlt.config_keys('alias').each do |command|
9
+ args = Rlt.config('alias', command).split(' ')
10
+ CommandsMap.add_alias(command, args)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rlt/commands_map'
4
+
5
+ module Rlt
6
+ class RegisterCommands
7
+ # rubocop:disable Metrics/MethodLength
8
+ def self.register
9
+ git_native_commands.each do |command|
10
+ desc = 'Git native command'
11
+ klass = Commands::GitNativeCommandBuilder.build(command)
12
+ CommandsMap.add command, desc, klass
13
+ end
14
+
15
+ CommandsMap.add 'switch', 'Switch to branch', Commands::SwitchCommand
16
+ CommandsMap.add 'cmt', 'Commit in clear way', Commands::CmtCommand
17
+ end
18
+ # rubocop:enable Metrics/MethodLength
19
+
20
+ def self.git_native_commands
21
+ %w[add archive bisect branch checkout clone commit config diff fetch grep init
22
+ log merge mv pull push rebase remote reset rm show status tag]
23
+ end
24
+ end
25
+ end
data/lib/rlt/shell.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'etc'
4
+ require 'tty-command'
5
+
6
+ class Shell
7
+ def initialize(opts = {})
8
+ printer = opts[:no_output] ? :null : :quiet
9
+ @cmd = TTY::Command.new(printer: printer, pty: true, dry_run: Rlt.debug)
10
+ end
11
+
12
+ def run(*args)
13
+ result = @cmd.run(*args, user: Etc.getlogin)
14
+ puts '' if Rlt.debug
15
+ result
16
+ end
17
+
18
+ def run_safely(*args)
19
+ result = @cmd.run!(*args, user: Etc.getlogin)
20
+ puts '' if Rlt.debug
21
+ result
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rlt
4
+ VERSION = '0.1.1'.freeze
5
+ end
data/lib/rlt.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rlt/version'
4
+ require 'rlt/shell'
5
+ require 'rlt/logger'
6
+ require 'rlt/base_command'
7
+ require 'rlt/git_native_command_builder'
8
+ Dir["#{__dir__}/rlt/commands/**/*.rb"].each { |f| require f }
9
+ require 'rlt/register_commands'
10
+ require 'rlt/register_aliases'
11
+ require 'rlt/command_runner'
12
+ require 'rlt/config'
13
+
14
+ module Rlt
15
+ def self.debug
16
+ ENV['RLT_DEBUG']
17
+ end
18
+ extend Config
19
+ extend CommandRunner
20
+
21
+ RegisterCommands.register
22
+ RegisterAliases.register
23
+ end
Binary file
data/rlt.gemspec ADDED
@@ -0,0 +1,33 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('lib', __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'rlt/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'rlt'
10
+ spec.version = Rlt::VERSION
11
+ spec.authors = ['Paul Lee']
12
+ spec.email = ['paul@valuepotion.com']
13
+
14
+ spec.summary = 'Go back to command line with `rlt`, the easier git'
15
+ spec.description = spec.summary
16
+ spec.homepage = 'https://github.com/eunjae-lee/rlt'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_dependency 'pastel', '~> 0.7.2'
27
+ spec.add_dependency 'tty-command', '~> 0.8.0'
28
+ spec.add_dependency 'tty-prompt', '~> 0.16.1'
29
+ spec.add_development_dependency 'bundler', '~> 1.16'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'rubocop'
33
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rlt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Lee
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pastel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-command
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-prompt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.16.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.16.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Go back to command line with `rlt`, the easier git
112
+ email:
113
+ - paul@valuepotion.com
114
+ executables:
115
+ - rlt
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rlt.sample.yml"
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".ruby-version"
124
+ - ".travis.yml"
125
+ - CODE_OF_CONDUCT.md
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - LICENSE.txt
129
+ - README.md
130
+ - Rakefile
131
+ - bin/console
132
+ - bin/setup
133
+ - exe/rlt
134
+ - lib/rlt.rb
135
+ - lib/rlt/base_command.rb
136
+ - lib/rlt/command_runner.rb
137
+ - lib/rlt/commands/cmt_command.rb
138
+ - lib/rlt/commands/switch_command.rb
139
+ - lib/rlt/commands_map.rb
140
+ - lib/rlt/config.rb
141
+ - lib/rlt/git_native_command_builder.rb
142
+ - lib/rlt/logger.rb
143
+ - lib/rlt/register_aliases.rb
144
+ - lib/rlt/register_commands.rb
145
+ - lib/rlt/shell.rb
146
+ - lib/rlt/version.rb
147
+ - releases/rlt-0.1.0.tar.gz
148
+ - rlt.gemspec
149
+ homepage: https://github.com/eunjae-lee/rlt
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.7.3
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Go back to command line with `rlt`, the easier git
173
+ test_files: []