Module: Spigoter::CLI::Init

Defined in:
lib/spigoter/cli/cli_init.rb

Overview

Module for generating the necessary files.

Author:

Class Method Summary collapse

Class Method Details

.generate_emptyObject



52
53
54
55
56
57
58
59
60
# File 'lib/spigoter/cli/cli_init.rb', line 52

def self.generate_empty
  open('plugins.yml', 'w+') do |f|
    f << "---\n"
    f << "Plugins:\n"
    f << "  # Plugin1:\n"
    f << "    # type: {curse|devbukkit|....}\n"
    f << "    # url: http://something.com\n"
  end
end

.generate_pluginsObject



32
33
34
35
36
37
38
# File 'lib/spigoter/cli/cli_init.rb', line 32

def self.generate_plugins
  if Dir.exist?('plugins') && !Dir['plugins/*.jar'].empty?
    generate_with_plugins
  else
    generate_empty
  end
end

.generate_spigoterObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/spigoter/cli/cli_init.rb', line 21

def self.generate_spigoter
  open('spigoter.yml', 'w+') do |f|
    f << "---\n"
    f << "Spigoter:\n"
    f << "  build_dir: build\n"
    f << "  plugins_dir: plugins\n"
    f << "  javaparams: \"-Xms1G -Xmx2G\"\n"
    f << "  spigot_version: latest\n"
  end
end

.generate_with_pluginsObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/spigoter/cli/cli_init.rb', line 40

def self.generate_with_plugins
  open('plugins.yml', 'w+') do |f|
    f << "---\n"
    f << "Plugins:\n"
    Dir['plugins/*.jar'].each do |plg|
      f << "  #{File.basename(plg).gsub(/.jar/, '')}:\n"
      f << "    # type: {curse|devbukkit|....}\n"
      f << "    # url: http://something.com\n"
    end
  end
end

.initObject



11
12
13
# File 'lib/spigoter/cli/cli_init.rb', line 11

def self.init
  ->(*) { main }
end

.mainObject



15
16
17
18
19
# File 'lib/spigoter/cli/cli_init.rb', line 15

def self.main(*)
  Log.info 'Generating files!'
  File.exist?('spigoter.yml') ? Log.warn('spigoter.yml alredy exists') : generate_spigoter
  File.exist?('plugins.yml')  ? Log.warn('plugins.yml alredy exists')  : generate_plugins
end