umarell 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/umarell/arguments.rb +71 -0
- data/lib/umarell/cli.rb +24 -41
- data/lib/umarell/command.rb +34 -0
- data/lib/umarell/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef5048068ece7c6751a487e6ac24aea679ff95887041ecb5f216f78d3462ac2e
|
4
|
+
data.tar.gz: b071681a9849c7619459c2966e2d6373950eb38fe6e8d602292f8bfd7d0a0cbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f98de58f255d491a759296b0e7e58365c477e2323027fbcdb7959e526296ffb708ab384a18fdab16489bdcf74311d860f1153b5294e8ce518c10e8c81ba3cbe
|
7
|
+
data.tar.gz: 49bf2435d7b4ff029d1b424e2359c13a89e6fac5f463273207ca8806a79d800f0e23485a2c0d57acf3c6403c36c0f467d4bb3422825ba655804851e2104351da
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
module Umarell
|
6
|
+
# The class responsible of parsing command line arguments
|
7
|
+
class Arguments
|
8
|
+
attr_reader :autofix, :target
|
9
|
+
|
10
|
+
alias autofix? autofix
|
11
|
+
|
12
|
+
MODIFIED_FILES_TARGET = '`git ls-files -mo --exclude-standard %s`'
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@autofix = false
|
16
|
+
@modified = false
|
17
|
+
@target = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
# Parse command line arguments
|
21
|
+
def parse
|
22
|
+
parse_options
|
23
|
+
parse_target
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def parse_options
|
29
|
+
OptionParser.new do |opts|
|
30
|
+
opts.banner = 'Usage: umarell [options] [target]'
|
31
|
+
on_autofix(opts)
|
32
|
+
on_modified(opts)
|
33
|
+
on_version(opts)
|
34
|
+
end.parse!
|
35
|
+
rescue OptionParser::InvalidOption => e
|
36
|
+
exit_with_message("#{e.message}, see 'umarell --help'", 1)
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_target
|
40
|
+
last_argument = ARGV.pop
|
41
|
+
@target = if @modified
|
42
|
+
MODIFIED_FILES_TARGET % last_argument
|
43
|
+
else
|
44
|
+
last_argument
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def on_autofix(opts)
|
49
|
+
opts.on('-a', '--autofix', 'Autofix violations (if supported)') do
|
50
|
+
@autofix = true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def on_modified(opts)
|
55
|
+
opts.on('-m', '--modified', 'Run on modified files') do
|
56
|
+
@modified = true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def on_version(opts)
|
61
|
+
opts.on_tail('-v', '--version', 'Show version') do
|
62
|
+
exit_with_message(Version::STRING)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def exit_with_message(message, code = 0)
|
67
|
+
puts "umarell: #{message}"
|
68
|
+
exit code
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/umarell/cli.rb
CHANGED
@@ -1,70 +1,53 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'arguments'
|
4
|
+
require_relative 'command'
|
4
5
|
|
5
6
|
module Umarell
|
6
7
|
TOOLS = {
|
7
|
-
|
8
|
-
brakeman
|
9
|
-
|
10
|
-
|
11
|
-
rails_best_practices:
|
12
|
-
|
8
|
+
'bundler-audit' => ['check', '--update'],
|
9
|
+
'brakeman' => ['-w2', '-q'],
|
10
|
+
'rubocop' => [],
|
11
|
+
'reek' => [],
|
12
|
+
'rails_best_practices': [],
|
13
|
+
'fasterer' => []
|
13
14
|
}.freeze
|
14
15
|
|
16
|
+
AUTOFIX_SUPPORT = ['rubocop'].freeze
|
17
|
+
|
15
18
|
# The class responsible of handling command line logic
|
16
19
|
class CLI
|
17
|
-
def initialize(tools = TOOLS)
|
20
|
+
def initialize(tools = TOOLS, arguments = Arguments.new)
|
18
21
|
@tools = tools
|
19
|
-
@
|
20
|
-
@args = {}
|
21
|
-
@target = ''
|
22
|
+
@arguments = arguments
|
22
23
|
end
|
23
24
|
|
24
25
|
# Entry point to start the application
|
25
26
|
def run
|
26
|
-
|
27
|
+
@arguments.parse
|
27
28
|
run_commands
|
28
29
|
end
|
29
30
|
|
30
31
|
private
|
31
32
|
|
32
|
-
def parse_args
|
33
|
-
parse_options
|
34
|
-
@target = ARGV.pop
|
35
|
-
@args[:rubocop] = ['-a'] if @autofix
|
36
|
-
end
|
37
|
-
|
38
|
-
def parse_options
|
39
|
-
OptionParser.new do |opts|
|
40
|
-
opts.banner = 'Usage: umarell [options] [target]'
|
41
|
-
|
42
|
-
opts.on('-a', '--autofix', 'Autofix violations (if supported)') do
|
43
|
-
@autofix = true
|
44
|
-
end
|
45
|
-
opts.on_tail('-v', '--version', 'Show version') do
|
46
|
-
puts Version::STRING
|
47
|
-
exit
|
48
|
-
end
|
49
|
-
end.parse!
|
50
|
-
end
|
51
|
-
|
52
33
|
def run_commands
|
53
|
-
@tools.each do |name,
|
54
|
-
|
34
|
+
@tools.each do |name, options|
|
35
|
+
arguments = command_arguments(name, options)
|
36
|
+
Command.new(name, arguments).run
|
55
37
|
end
|
56
38
|
end
|
57
39
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
full_command = "#{command} #{args.join(' ')} #{@target}"
|
40
|
+
def command_arguments(name, options)
|
41
|
+
command_arguments = command_options(name, options)
|
42
|
+
return command_arguments unless @arguments.target
|
62
43
|
|
63
|
-
|
44
|
+
command_arguments + [@arguments.target]
|
64
45
|
end
|
65
46
|
|
66
|
-
def
|
67
|
-
|
47
|
+
def command_options(name, base_options)
|
48
|
+
return base_options unless AUTOFIX_SUPPORT.include?(name)
|
49
|
+
|
50
|
+
base_options + ['-a']
|
68
51
|
end
|
69
52
|
end
|
70
53
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Umarell
|
4
|
+
# The class responsible for running commands
|
5
|
+
class Command
|
6
|
+
def initialize(name, arguments = [])
|
7
|
+
@name = name
|
8
|
+
@arguments = arguments
|
9
|
+
end
|
10
|
+
|
11
|
+
# Run the command
|
12
|
+
def run
|
13
|
+
system "echo '#{header}'; #{self}; echo '#{footer}'"
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"#{@name} #{@arguments.join(' ')}"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def header
|
23
|
+
decorate_message("Running #{@name}")
|
24
|
+
end
|
25
|
+
|
26
|
+
def footer
|
27
|
+
decorate_message("#{@name} run complete\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
def decorate_message(string)
|
31
|
+
"\e[1;94m~~~~~~~ [Umarell] #{string}\e[0m"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/umarell/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umarell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filippo Liverani
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brakeman
|
@@ -205,7 +205,9 @@ files:
|
|
205
205
|
- README.md
|
206
206
|
- exe/umarell
|
207
207
|
- lib/umarell.rb
|
208
|
+
- lib/umarell/arguments.rb
|
208
209
|
- lib/umarell/cli.rb
|
210
|
+
- lib/umarell/command.rb
|
209
211
|
- lib/umarell/version.rb
|
210
212
|
homepage: https://github.com/nebulab/umarell
|
211
213
|
licenses:
|