abtion-aid 0.2.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.
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aid
4
+ module Scripts
5
+ end
6
+ end
@@ -0,0 +1,157 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aid
4
+ module Scripts
5
+ class Doctor < Aid::Script
6
+ def self.description
7
+ 'Checks the health of your development environment'
8
+ end
9
+
10
+ def self.help
11
+ 'doctor - helps you diagnose any setup issues with this application'
12
+ end
13
+
14
+ def initialize(*args)
15
+ super
16
+ @checks = []
17
+ end
18
+
19
+ def check(**options)
20
+ check = Check.new(options)
21
+ @checks << check
22
+
23
+ check.run!
24
+ end
25
+
26
+ def run
27
+ puts <<~HELP
28
+ To implement this script for your repository, create the following
29
+ file in #{colorize(:green, "#{aid_directory}/doctor.rb")}:
30
+
31
+ class Doctor < Aid::Scripts::Doctor
32
+ def run
33
+ check_phantomjs_installed
34
+ end
35
+
36
+ private
37
+
38
+ def check_phantomjs_installed
39
+ check name: "PhantomJS installed",
40
+ command: "which phantomjs",
41
+ remedy: command("brew install phantomjs")
42
+ end
43
+ end
44
+
45
+ You can add as many checks to your script as you want.
46
+ HELP
47
+
48
+ exit
49
+ end
50
+
51
+ def problems
52
+ @checks.map(&:problems).flatten
53
+ end
54
+
55
+ def exit_code
56
+ problems.size
57
+ end
58
+
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
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aid
4
+ module Scripts
5
+ class Help < Aid::Script
6
+ attr_reader :script
7
+
8
+ def initialize(*argv)
9
+ super
10
+
11
+ script_name = argv.first
12
+ @script = Aid::Script.scripts[script_name]
13
+ end
14
+
15
+ def self.description
16
+ 'Displays help information'
17
+ end
18
+
19
+ def self.help
20
+ ''
21
+ end
22
+
23
+ def run
24
+ if script
25
+ puts "Help for #{colorize(:light_blue, script.name)}:"
26
+
27
+ puts script.help
28
+ puts
29
+ else
30
+ basic_usage
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def basic_usage
37
+ puts "Usage: aid #{colorize(:light_blue, '[script name]')}"
38
+ puts
39
+ puts 'Specify a specific script to run, options are: '
40
+ puts
41
+
42
+ scripts = Hash[Aid::Script.scripts.sort]
43
+
44
+ names_and_descriptions = scripts.map do |name, script|
45
+ [
46
+ colorize(:light_green, name),
47
+ colorize(:light_blue, script.description)
48
+ ]
49
+ end
50
+
51
+ padding = names_and_descriptions.map { |name, _| name.length }.max
52
+
53
+ names_and_descriptions.each do |name, description|
54
+ puts format(" %-#{padding}s %s", name, description)
55
+ end
56
+
57
+ puts
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aid
4
+ module Scripts
5
+ class Init < Aid::Script
6
+ def self.description
7
+ 'Sets up aid in your project'
8
+ end
9
+
10
+ def run
11
+ step 'Creating .aid directory' do
12
+ system! "mkdir -p #{aid_directory}"
13
+ end
14
+
15
+ puts
16
+ puts 'All done! To create your first script, run '\
17
+ "#{colorize(:green, 'aid new [script-name]')}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aid
4
+ module Scripts
5
+ class New < Aid::Script
6
+ def self.description
7
+ 'Generates a new script in the aid directory'
8
+ end
9
+
10
+ def self.help
11
+ <<~HELP
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
17
+ HELP
18
+ end
19
+
20
+ def run
21
+ exit_with_help! unless script_name
22
+ check_for_aid_directory!
23
+
24
+ step "Creating #{output_path}" do
25
+ File.open(output_path, 'wb') do |fp|
26
+ fp.write(template)
27
+ end
28
+
29
+ puts
30
+ print 'Successfully created '
31
+ puts colorize(:green, output_path)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def output_path
38
+ "#{aid_directory}/#{output_filename}"
39
+ end
40
+
41
+ def output_filename
42
+ "#{script_name.tr('-', '_')}.rb"
43
+ end
44
+
45
+ def check_for_aid_directory!
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."
50
+ end
51
+
52
+ def template
53
+ <<~RUBY
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
65
+ end
66
+ RUBY
67
+ end
68
+
69
+ def class_name
70
+ script_name
71
+ .split('-')
72
+ .map { |token| token[0].upcase + token[1..-1] }
73
+ .join
74
+ end
75
+
76
+ def script_name
77
+ argv.first
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aid
4
+ VERSION = '0.2.0'
5
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abtion-aid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Abtion
8
+ - David Balatero
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2019-11-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.0.1
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.0.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: pry
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubocop
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description:
85
+ email:
86
+ - mail@abtion.com
87
+ executables:
88
+ - aid
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - ".solargraph.yml"
96
+ - ".travis.yml"
97
+ - CHANGELOG.md
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - aid.gemspec
103
+ - bin/console
104
+ - bin/setup
105
+ - examples/begin.rb
106
+ - examples/ci.rb
107
+ - examples/data_dump.rb
108
+ - examples/doctor.rb
109
+ - examples/eslint.rb
110
+ - examples/finish.rb
111
+ - examples/mocha.rb
112
+ - examples/pr.rb
113
+ - examples/pushit.rb
114
+ - examples/rspec.rb
115
+ - examples/rubocop.rb
116
+ - examples/slim_lint.rb
117
+ - examples/test.rb
118
+ - examples/update.rb
119
+ - exe/aid
120
+ - lib/aid.rb
121
+ - lib/aid/colorize.rb
122
+ - lib/aid/inheritable.rb
123
+ - lib/aid/plugins.rb
124
+ - lib/aid/script.rb
125
+ - lib/aid/scripts.rb
126
+ - lib/aid/scripts/doctor.rb
127
+ - lib/aid/scripts/help.rb
128
+ - lib/aid/scripts/init.rb
129
+ - lib/aid/scripts/new.rb
130
+ - lib/aid/version.rb
131
+ homepage: https://github.com/abtion/aid
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.7.7
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: A library to make repo scripts easy and discoverable.
155
+ test_files: []