Class: Danger::NewPlugin

Inherits:
Runner
  • Object
show all
Defined in:
lib/danger/commands/new_plugin.rb

Instance Method Summary collapse

Methods inherited from Runner

options, #post_results

Constructor Details

#initialize(argv) ⇒ NewPlugin

Returns a new instance of NewPlugin.



6
7
8
# File 'lib/danger/commands/new_plugin.rb', line 6

def initialize(argv)
  super
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/danger/commands/new_plugin.rb', line 14

def run
  require 'fileutils'

  puts "Must be lower case, and use a '_' between words. Do not use '.'".green
  puts "examples: 'number_of_emojis', 'ensure_pr_title_contains_keyword'".green
  puts "Name of your new plugin: "
  name = STDIN.gets.strip

  dir = Danger.gem_path
  content = File.read(File.join(dir, "lib", "assets", "PluginTemplate.rb.template"))
  content.gsub!("[[CLASS_NAME]]", name.danger_class)

  plugins_path = "danger_plugins"
  FileUtils.mkdir_p("plugins_path") unless File.directory?(plugins_path)

  output_path = File.join(plugins_path, "#{name}.rb")
  raise "File '#{output_path}' already exists!" if File.exist?(output_path)
  File.write(output_path, content)

  puts ""
  puts "Successfully created new plugin at path '#{output_path}'".green
  puts "Add this to your `Dangerfile` to use it:"
  puts ""
  puts "#{name}(parameter1: 123, parameter2: \"Club Mate\")".blue
  puts ""
  puts "Enjoy ✨"
end

#validate!Object



10
11
12
# File 'lib/danger/commands/new_plugin.rb', line 10

def validate!
  super
end