Class: Terraspace::CLI::New::Project

Inherits:
Sequence
  • Object
show all
Defined in:
lib/terraspace/cli/new/project.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Sequence

base_options, component_options

Methods included from Util::Logging

#logger

Class Method Details

.project_optionsObject



3
4
5
6
7
8
9
10
11
# File 'lib/terraspace/cli/new/project.rb', line 3

def self.project_options
  [
    [:bundle, type: :boolean, default: true, desc: "Runs bundle install on the project"],
    [:config, type: :boolean, default: true, desc: "Whether or not to generate config files."],
    [:force, aliases: %w[y], type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
    [:quiet, type: :boolean, desc: "Quiet output."],
    [:test_structure, type: :boolean, desc: "Create project bootstrap test structure."],
  ]
end

Instance Method Details

#bundle_installObject



68
69
70
71
72
73
74
75
76
# File 'lib/terraspace/cli/new/project.rb', line 68

def bundle_install
  return if @options[:bundle] == false
  log "=> Installing dependencies with: bundle install"
  Bundler.with_unbundled_env do
    bundle = "BUNDLE_IGNORE_CONFIG=1 bundle install"
    bundle << " > /dev/null 2>&1" if @options[:quiet]
    system(bundle, chdir: name)
  end
end

#create_baseObject



26
27
28
29
# File 'lib/terraspace/cli/new/project.rb', line 26

def create_base
  plugin_template_source("base", "project")
  directory ".", "#{name}"
end

#create_projectObject

Will generate config folder from

1. terraspace code lang templates or
2. example lang templates from provider gems


36
37
38
39
40
41
42
43
44
45
# File 'lib/terraspace/cli/new/project.rb', line 36

def create_project
  plugin_template_source(@options[:lang], "project") # IE: plugin_template_source("hcl", "project")

  options = @options[:config] == false ? {exclude_pattern: "config" } : {}
  directory ".", "#{name}", options

  if @options[:config] == false
    empty_directory("#{name}/config")
  end
end

#create_starter_moduleObject



53
54
55
56
# File 'lib/terraspace/cli/new/project.rb', line 53

def create_starter_module
  return unless @options[:examples]
  Module.start(component_args("example", name))
end

#create_starter_stackObject



58
59
60
61
# File 'lib/terraspace/cli/new/project.rb', line 58

def create_starter_stack
  return unless @options[:examples]
  Stack.start(component_args("demo", name))
end

#create_testObject



63
64
65
66
# File 'lib/terraspace/cli/new/project.rb', line 63

def create_test
  return unless @options[:test_structure]
  Test::Bootstrap.start(["--dir", name])
end

#creating_messagingObject



22
23
24
# File 'lib/terraspace/cli/new/project.rb', line 22

def creating_messaging
  log "=> Creating new project called #{name}."
end

#empty_dirsObject



47
48
49
50
51
# File 'lib/terraspace/cli/new/project.rb', line 47

def empty_dirs
  return if @options[:examples]
  empty_directory("#{name}/app/modules")
  empty_directory("#{name}/app/stacks")
end

#welcome_message_examplesObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/terraspace/cli/new/project.rb', line 78

def welcome_message_examples
  return unless options[:examples]
  log <<~EOL
    #{"="*64}
    Congrats! You have successfully created a terraspace project.
    Check out the created files. Adjust to the examples and then deploy with:

        cd #{name}
        terraspace up demo -y   # to deploy
        terraspace down demo -y # to destroy

    More info: https://terraspace.cloud/
  EOL
end

#welcome_message_no_examplesObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/terraspace/cli/new/project.rb', line 93

def welcome_message_no_examples
  return if options[:examples]
  log <<~EOL
    #{"="*64}
    Congrats! You have successfully created a terraspace project.
    Check out the created files.

        cd #{name}

    You can create starter modules and stacks with their generators:

        terraspace new module example
        terraspace new stack demo

    Add your code to them, and deploy when you are ready:

        terraspace up demo -y   # to deploy

    Destroy with:

        terraspace down demo -y # to destroy

    More info: https://terraspace.cloud/
  EOL
end