Class: Forger::New

Inherits:
Sequence
  • Object
show all
Defined in:
lib/forger/new.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Sequence

source_root

Class Method Details

.cli_optionsObject

Ugly, but when the class_option is only defined in the Thor::Group class it doesnt show up with cli-template new help :( If anyone knows how to fix this let me know. Also options from the cli can be pass through to here



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/forger/new.rb', line 9

def self.cli_options
  [
    [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
    [:git, type: :boolean, default: true, desc: "Git initialize the project"],
    [:iam, desc: "iam_instance_profile to use in the profiles/default.yml"],
    [:key_name, desc: "key name to use with launched instance in profiles/default.yml"],
    [:security_group, desc: "Security group to use. For config/variables/development.rb network settings."],
    [:subnet, desc: "Subnet to use. For config/variables/development.rb network settings."],
    [:vpc_id, desc: "Vpc id. For config/variables/development.rb network settings. Will use default sg and subnet"],
  ]
end

Instance Method Details

#bundle_installObject



44
45
46
47
48
# File 'lib/forger/new.rb', line 44

def bundle_install
  Bundler.with_clean_env do
    system("BUNDLE_IGNORE_CONFIG=1 bundle install")
  end
end

#configure_network_settingsObject



25
26
27
28
29
30
31
# File 'lib/forger/new.rb', line 25

def configure_network_settings
  return if ENV['TEST']

  network = Network.new(@options[:vpc_id]) # used for default settings
  @subnet = @options[:subnet] || network.subnet_ids.first
  @security_group = @options[:security_group] || network.security_group_id
end

#create_projectObject



33
34
35
36
37
38
# File 'lib/forger/new.rb', line 33

def create_project
  copy_project
  destination_root = "#{Dir.pwd}/#{project_name}"
  self.destination_root = destination_root
  FileUtils.cd("#{Dir.pwd}/#{project_name}")
end

#git_initObject



50
51
52
53
54
55
56
57
58
# File 'lib/forger/new.rb', line 50

def git_init
  return if !options[:git]
  return unless git_installed?
  return if File.exist?(".git") # this is a clone repo

  run("git init")
  run("git add .")
  run("git commit -m 'first commit'")
end

#make_executableObject



40
41
42
# File 'lib/forger/new.rb', line 40

def make_executable
  chmod("exe", 0755 & ~File.umask, verbose: false) if File.exist?("exe")
end

#user_messageObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/forger/new.rb', line 60

def user_message
  puts <<-EOL
#{"="*64}
Congrats 🎉 You have successfully generated a starter forger project.

Test the CLI:

  cd #{project_name}
  forger create box --noop # dry-run to see the tmp/user-data.txt script
  forger create box # live-run
  forger create box --ssh
EOL
end