rlt 0.1.5 → 0.1.6

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.
@@ -1,78 +0,0 @@
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
- save_stash_if_any
13
- switch(branch_name)
14
- apply_stash_if_any(branch_name)
15
- end
16
-
17
- def self.change_branch_name(config, branch_name)
18
- return branch_name if exclude?(config, branch_name)
19
- branch_name_template = config[CONF_BRANCH_NAME_TEMPLATE]
20
- return branch_name if branch_name_template.nil?
21
- ERB.new(branch_name_template).result binding
22
- end
23
-
24
- def self.save_stash_if_any
25
- return if `git status -s`.strip.empty?
26
- Logger.info 'Saving stash'
27
- Shell.new.run 'git', 'stash', 'save', '--include-untracked', 'Auto stash'
28
- end
29
-
30
- def self.apply_stash_if_any(branch_name)
31
- name = stash_name(branch_name)
32
- return if name.nil?
33
- Logger.info 'Applied stash'
34
- Shell.new.run 'git', 'stash', 'apply', name, '--index'
35
- Shell.new.run 'git', 'stash', 'drop', name
36
- end
37
-
38
- def self.exclude?(config, branch_name)
39
- list = %w[master develop] + (config['exclude'] || [])
40
- list.include? branch_name
41
- end
42
-
43
- def self.switch(branch_name)
44
- create_and_checkout(branch_name) if checkout(branch_name).failure?
45
- end
46
-
47
- def self.checkout(branch_name)
48
- result = Shell.new(no_output: true).run_safely 'git', 'checkout', branch_name
49
- Logger.info "Switched to '#{branch_name}'." unless result.failure?
50
- result
51
- end
52
-
53
- def self.create_and_checkout(branch_name)
54
- Shell.new(no_output: true).run 'git', 'checkout', '-b', branch_name
55
- Logger.info "Created & Switched to '#{branch_name}'."
56
- end
57
-
58
- def self.print_help(*_arguments)
59
- puts 'USAGE:'
60
- puts ' rlt switch <branch_name>'
61
- puts ''
62
- puts ' This command switches to <branch_name>. It creates the branch if it does not exist.'
63
- end
64
-
65
- def self.valid_parameters?(*arguments)
66
- arguments.size == 1
67
- end
68
-
69
- def self.stash_name(branch_name)
70
- line = `git stash list`.strip.split("\n").find do |line|
71
- line.split(':')[1].strip == "On #{branch_name}"
72
- end
73
- return nil if line.nil?
74
- line.split(':').first
75
- end
76
- end
77
- end
78
- end
@@ -1,37 +0,0 @@
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
@@ -1,25 +0,0 @@
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 DELETED
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pastel'
4
-
5
- module Rlt
6
- class Logger
7
- def self.verbose(msg)
8
- puts ColoredText.verbose(msg)
9
- end
10
-
11
- def self.info(msg)
12
- puts ColoredText.info(msg)
13
- end
14
-
15
- def self.desc(msg)
16
- puts ColoredText.desc(msg)
17
- end
18
-
19
- def self.warn(msg)
20
- puts ColoredText.warn(msg)
21
- end
22
-
23
- def self.error(msg)
24
- puts ColoredText.error(msg)
25
- end
26
- end
27
- end
@@ -1,14 +0,0 @@
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
@@ -1,25 +0,0 @@
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 DELETED
@@ -1,23 +0,0 @@
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
Binary file
data/rlt.gemspec DELETED
@@ -1,34 +0,0 @@
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
- spec.required_ruby_version = '>= 2.3.0'
26
-
27
- spec.add_dependency 'pastel', '~> 0.7.2'
28
- spec.add_dependency 'tty-command', '~> 0.8.0'
29
- spec.add_dependency 'tty-prompt', '~> 0.16.1'
30
- spec.add_development_dependency 'bundler', '~> 1.16'
31
- spec.add_development_dependency 'rake', '~> 10.0'
32
- spec.add_development_dependency 'rspec', '~> 3.0'
33
- spec.add_development_dependency 'rubocop'
34
- end