aid 0.1.3 → 0.2.2

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,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aid
2
4
  class Script
3
5
  include Aid::Colorize
4
6
  include Aid::Inheritable
5
7
 
6
8
  def self.name
7
- klass_name = self.to_s.split('::').last
9
+ klass_name = to_s.split('::').last
8
10
 
9
11
  klass_name
10
12
  .scan(/[A-Z][a-z0-9]*/)
@@ -34,7 +36,7 @@ module Aid
34
36
  end
35
37
 
36
38
  def self.description
37
- ""
39
+ ''
38
40
  end
39
41
 
40
42
  def help
@@ -64,7 +66,7 @@ module Aid
64
66
  end
65
67
 
66
68
  def system!(*args)
67
- puts colorize(:command, args.join(" "))
69
+ puts colorize(:command, args.join(' '))
68
70
  system(*args) || abort(colorize(:error, "\n== Command #{args} failed =="))
69
71
  end
70
72
 
@@ -91,7 +93,7 @@ module Aid
91
93
  private
92
94
 
93
95
  def aid_directory
94
- "./.aid"
96
+ './.aid'
95
97
  end
96
98
  end
97
99
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aid
2
4
  module Scripts
3
5
  end
@@ -1,45 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aid
2
4
  module Scripts
3
5
  class Doctor < Aid::Script
4
- class Check
5
- include Aid::Colorize
6
-
7
- attr_reader :name, :command, :remedy, :problems
8
-
9
- def initialize(name:, command:, remedy:)
10
- @name = name
11
- @command = command
12
- @remedy = remedy
13
- @problems = []
14
- end
15
-
16
- def run!
17
- print "Checking: #{name}... "
18
-
19
- success = if command.respond_to?(:call)
20
- command.call
21
- else
22
- system "#{command} > /dev/null 2>&1"
23
- end
24
-
25
- if success
26
- puts 'OK'
27
- else
28
- print colorize(:error, 'F')
29
- fix = remedy.respond_to?(:join) ? remedy.join(" ") : remedy
30
- puts "\n To fix: #{colorize(:command, fix)}\n\n"
31
-
32
- problems << name
33
- end
34
- end
35
- end
36
-
37
6
  def self.description
38
- "Checks the health of your development environment"
7
+ 'Checks the health of your development environment'
39
8
  end
40
9
 
41
10
  def self.help
42
- "doctor - helps you diagnose any setup issues with this application"
11
+ 'doctor - helps you diagnose any setup issues with this application'
43
12
  end
44
13
 
45
14
  def initialize(*args)
@@ -56,8 +25,8 @@ module Aid
56
25
 
57
26
  def run
58
27
  puts <<~HELP
59
- To implement this script for your repository, create the following
60
- file in #{colorize(:green, "#{aid_directory}/doctor.rb")}:
28
+ To implement this script for your repository, create the following
29
+ file in #{colorize(:green, "#{aid_directory}/doctor.rb")}:
61
30
 
62
31
  class Doctor < Aid::Scripts::Doctor
63
32
  def run
@@ -73,7 +42,7 @@ module Aid
73
42
  end
74
43
  end
75
44
 
76
- You can add as many checks to your script as you want.
45
+ You can add as many checks to your script as you want.
77
46
  HELP
78
47
 
79
48
  exit
@@ -87,8 +56,101 @@ module Aid
87
56
  problems.size
88
57
  end
89
58
 
90
- def command(s)
91
- "run #{colorize :command, s}"
59
+ def command(cmd)
60
+ CommandRemedy.new(cmd)
61
+ end
62
+
63
+ class Remedy
64
+ def initialize(message)
65
+ @message = message
66
+ end
67
+
68
+ def auto_fixable?
69
+ false
70
+ end
71
+
72
+ def auto_fix!
73
+ # By default, we don't know how to auto-fix
74
+ end
75
+
76
+ def to_s
77
+ message
78
+ end
79
+
80
+ private
81
+
82
+ attr_reader :message
83
+ end
84
+
85
+ class CommandRemedy < Remedy
86
+ include Aid::Colorize
87
+
88
+ alias shell_command message
89
+
90
+ def initialize(shell_command)
91
+ super
92
+ end
93
+
94
+ def auto_fixable?
95
+ true
96
+ end
97
+
98
+ def auto_fix!
99
+ puts "==> running #{colorize(:command, "$ #{shell_command}")}"
100
+ system(shell_command)
101
+ end
102
+
103
+ def to_s
104
+ "run #{colorize :command, shell_command}"
105
+ end
106
+ end
107
+
108
+ class Check
109
+ include Aid::Colorize
110
+
111
+ attr_reader :name, :command, :remedy, :problems
112
+
113
+ def initialize(name:, command:, remedy:)
114
+ @name = name
115
+ @command = command
116
+ @remedy = remedy.is_a?(Remedy) ? remedy : Remedy.new(remedy)
117
+ @problems = []
118
+ @checked_once = false
119
+ end
120
+
121
+ def run!
122
+ print "Checking: #{name}... "
123
+
124
+ success = run_command
125
+
126
+ if success
127
+ puts 'OK'
128
+ else
129
+ puts colorize(:error, 'F')
130
+
131
+ if @checked_once || !remedy.auto_fixable?
132
+ puts "\n To fix: #{remedy}\n\n"
133
+ problems << name
134
+ elsif remedy.auto_fixable?
135
+ @checked_once = true
136
+
137
+ puts '==> attempting autofix'
138
+ remedy.auto_fix!
139
+ puts '==> retrying check'
140
+ run!
141
+ end
142
+ end
143
+ end
144
+
145
+ private
146
+
147
+ def run_command
148
+ if command.respond_to?(:call)
149
+ command.call
150
+ else
151
+ system "#{command} > /dev/null 2>&1"
152
+ end
153
+ end
92
154
  end
93
155
  end
94
156
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aid
2
4
  module Scripts
3
5
  class Help < Aid::Script
@@ -11,11 +13,11 @@ module Aid
11
13
  end
12
14
 
13
15
  def self.description
14
- "Displays help information"
16
+ 'Displays help information'
15
17
  end
16
18
 
17
19
  def self.help
18
- ""
20
+ ''
19
21
  end
20
22
 
21
23
  def run
@@ -34,10 +36,12 @@ module Aid
34
36
  def basic_usage
35
37
  puts "Usage: aid #{colorize(:light_blue, '[script name]')}"
36
38
  puts
37
- puts "Specify a specific script to run, options are: "
39
+ puts 'Specify a specific script to run, options are: '
38
40
  puts
39
41
 
40
- names_and_descriptions = Aid::Script.scripts.map do |name, script|
42
+ scripts = Hash[Aid::Script.scripts.sort]
43
+
44
+ names_and_descriptions = scripts.map do |name, script|
41
45
  [
42
46
  colorize(:light_green, name),
43
47
  colorize(:light_blue, script.description)
@@ -47,7 +51,7 @@ module Aid
47
51
  padding = names_and_descriptions.map { |name, _| name.length }.max
48
52
 
49
53
  names_and_descriptions.each do |name, description|
50
- puts " %-#{padding}s %s" % [name, description]
54
+ puts format(" %-#{padding}s %s", name, description)
51
55
  end
52
56
 
53
57
  puts
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aid
2
4
  module Scripts
3
5
  class Init < Aid::Script
4
6
  def self.description
5
- "Sets up aid in your project"
7
+ 'Sets up aid in your project'
6
8
  end
7
9
 
8
10
  def run
9
- step "Creating .aid directory" do
11
+ step 'Creating .aid directory' do
10
12
  system! "mkdir -p #{aid_directory}"
11
13
  end
12
14
 
13
15
  puts
14
- puts "All done! To create your first script, run "\
15
- "#{colorize(:green, "aid new [script-name]")}"
16
+ puts 'All done! To create your first script, run '\
17
+ "#{colorize(:green, 'aid new [script-name]')}"
16
18
  end
17
19
  end
18
20
  end
@@ -1,20 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aid
2
4
  module Scripts
3
5
  class New < Aid::Script
4
6
  def self.description
5
- "Generates a new script in the aid directory"
7
+ 'Generates a new script in the aid directory'
6
8
  end
7
9
 
8
10
  def self.help
9
11
  <<~HELP
10
- Usage: aid new [script name]
11
-
12
- Generates a new script file in the aid script directory.
13
-
14
- Example:
15
- #{colorize(:green, "$ aid new my-script-name")}
16
-
17
- will generate a new script called my_script_name.rb
12
+ Usage: aid new [script name]
13
+ Generates a new script file in the aid script directory.
14
+ Example:
15
+ #{colorize(:green, '$ aid new my-script-name')}
16
+ will generate a new script called my_script_name.rb
18
17
  HELP
19
18
  end
20
19
 
@@ -23,12 +22,12 @@ module Aid
23
22
  check_for_aid_directory!
24
23
 
25
24
  step "Creating #{output_path}" do
26
- File.open(output_path, "wb") do |fp|
25
+ File.open(output_path, 'wb') do |fp|
27
26
  fp.write(template)
28
27
  end
29
28
 
30
29
  puts
31
- print "Successfully created "
30
+ print 'Successfully created '
32
31
  puts colorize(:green, output_path)
33
32
  end
34
33
  end
@@ -40,38 +39,36 @@ module Aid
40
39
  end
41
40
 
42
41
  def output_filename
43
- "#{script_name.gsub(/-/, "_")}.rb"
42
+ "#{script_name.tr('-', '_')}.rb"
44
43
  end
45
44
 
46
45
  def check_for_aid_directory!
47
- unless Dir.exist?(aid_directory)
48
- abort "The #{colorize(:green, aid_directory)} directory is "\
49
- "missing. Please run #{colorize(:green, "aid init")} to create it."
50
- end
46
+ return if Dir.exist?(aid_directory)
47
+
48
+ abort "The #{colorize(:green, aid_directory)} directory is "\
49
+ "missing. Please run #{colorize(:green, 'aid init')} to create it."
51
50
  end
52
51
 
53
52
  def template
54
53
  <<~RUBY
55
- class #{class_name} < Aid::Script
56
- def self.description
57
- "FILL ME IN"
54
+ class #{class_name} < Aid::Script
55
+ def self.description
56
+ "FILL ME IN"
57
+ end
58
+ def self.help
59
+ <<~HELP
60
+ Fill me in.
61
+ HELP
62
+ end
63
+ def run
64
+ end
58
65
  end
59
-
60
- def self.help
61
- <<~HELP
62
- Fill me in.
63
- HELP
64
- end
65
-
66
- def run
67
- end
68
- end
69
66
  RUBY
70
67
  end
71
68
 
72
69
  def class_name
73
70
  script_name
74
- .split("-")
71
+ .split('-')
75
72
  .map { |token| token[0].upcase + token[1..-1] }
76
73
  .join
77
74
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ require_relative '../version'
4
+
5
+ module Aid
6
+ module Scripts
7
+ class Version < Aid::Script
8
+ def self.description
9
+ 'Displays the current version'
10
+ end
11
+
12
+ def run
13
+ puts Aid::VERSION
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aid
2
- VERSION = "0.1.3"
4
+ VERSION = '0.2.2'
3
5
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Balatero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-20 00:00:00.000000000 Z
11
+ date: 2020-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
- version: '1.15'
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description:
56
84
  email:
57
85
  - dbalatero@gmail.com
@@ -62,6 +90,8 @@ extra_rdoc_files: []
62
90
  files:
63
91
  - ".gitignore"
64
92
  - ".rspec"
93
+ - ".rubocop.yml"
94
+ - ".solargraph.yml"
65
95
  - ".travis.yml"
66
96
  - CHANGELOG.md
67
97
  - Gemfile
@@ -89,12 +119,14 @@ files:
89
119
  - lib/aid.rb
90
120
  - lib/aid/colorize.rb
91
121
  - lib/aid/inheritable.rb
122
+ - lib/aid/plugins.rb
92
123
  - lib/aid/script.rb
93
124
  - lib/aid/scripts.rb
94
125
  - lib/aid/scripts/doctor.rb
95
126
  - lib/aid/scripts/help.rb
96
127
  - lib/aid/scripts/init.rb
97
128
  - lib/aid/scripts/new.rb
129
+ - lib/aid/scripts/version.rb
98
130
  - lib/aid/version.rb
99
131
  homepage: https://github.com/dbalatero/aid
100
132
  licenses:
@@ -115,8 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
147
  - !ruby/object:Gem::Version
116
148
  version: '0'
117
149
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.6.11
150
+ rubygems_version: 3.0.3
120
151
  signing_key:
121
152
  specification_version: 4
122
153
  summary: A library to make repo scripts easy and discoverable.