Class: Kubes::CLI::Init

Inherits:
Sequence
  • Object
show all
Defined in:
lib/kubes/cli/init.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Class Method Details

.optionsObject



3
4
5
6
7
8
9
10
11
# File 'lib/kubes/cli/init.rb', line 3

def self.options
  [
    [:app, aliases: ["a"], required: true, desc: "Docker repo name. Example: web. Generates .kubes/APP/resources folder"],
    [:force, aliases: ["y"], type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
    [:type, aliases: ["t"], default: "yaml", desc: "Type: dsl or yaml"],
    [:repo, required: true, desc: "Docker repo name. Example: user/repo. Configures .kubes/config.rb"],
    [:namespace, aliases: ["n"], desc: "Namespace to use, defaults to APP-ENV. IE: demo-dev"],
  ]
end

Instance Method Details

#adjust_gitignoreObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/kubes/cli/init.rb', line 85

def adjust_gitignore
  ignores = %w[
    .kubes/output
    .kubes/tmp
  ].map {|l| "#{l}\n"} # the readlines will have lines with \n so keep consistent for processing
  if File.exist?(".gitignore")
    lines = IO.readlines(".gitignore")
    if lines.detect { |l| l.include?('.kubes/tmp') }
      return # early
    else
      lines += ignores
    end
  else
    lines = ignores
  end

  text = lines.join('')
  IO.write(".gitignore", text)
  puts "Updated .gitignore"
end

#create_base_filesObject



64
65
66
67
# File 'lib/kubes/cli/init.rb', line 64

def create_base_files
  set_source("base")
  directory ".", "."
end

#create_dockefileObject



58
59
60
61
62
# File 'lib/kubes/cli/init.rb', line 58

def create_dockefile
  return if File.exist?("Dockerfile")
  set_source("docker")
  directory ".", "."
end

#create_dsl_filesObject



69
70
71
72
73
# File 'lib/kubes/cli/init.rb', line 69

def create_dsl_files
  return unless @options[:type] == "dsl"
  set_source("dsl")
  directory ".", ".", directory_options
end

#create_yaml_filesObject



75
76
77
78
79
# File 'lib/kubes/cli/init.rb', line 75

def create_yaml_files
  return if @options[:type] == "dsl"
  set_source("yaml")
  directory ".", ".", directory_options
end

#messageObject



81
82
83
# File 'lib/kubes/cli/init.rb', line 81

def message
  logger.info "Initialized .kubes folder"
end