Class: Heighliner::Cmds::Init

Inherits:
Heighliner::Cli show all
Defined in:
lib/heighliner/cmds/init.rb

Instance Attribute Summary

Attributes inherited from Heighliner::Cli

#use_steerfile

Instance Method Summary collapse

Methods inherited from Heighliner::Cli

all_subcommands_usage, #define_options, #initialize, register, run_command, #set_config, #start_services, #stop_app, #stop_services

Methods included from Heighliner::CliOptions

#option, #options

Constructor Details

This class inherits a constructor from Heighliner::Cli

Instance Method Details

#execute(_opts) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/heighliner/cmds/init.rb', line 16

def execute(_opts)
  return Optimist.die "Already initialized as #{envname}. Use 'heighliner deinit' to remove this environment first." if envname

  name = ARGV.shift
  return Optimist.die 'Needs environment name' if name.nil?

  init_config_for_env(name)
  save_config
end

#init_config_for_env(name) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/heighliner/cmds/init.rb', line 26

def init_config_for_env(name)
  Config.config[:envnames][Config.work_dir] = name
  Config.config[:envs][name] = {
    app_port: (largest_port + 1).to_s,
    db_port: (largest_port + 2).to_s
  }
  Config.config[:largest_port] = Config.config[:largest_port] + 2
end

#largest_portObject



35
36
37
# File 'lib/heighliner/cmds/init.rb', line 35

def largest_port
  Config.config[:largest_port]
end

#usageObject



6
7
8
9
10
11
12
13
14
# File 'lib/heighliner/cmds/init.rb', line 6

def usage
  <<~EOS
    Initializes a Heighliner environment and assigns ports for it in \`~/.heighliner/config.yml\`. When running \`heighliner up\` later the directory \`~/.heighliner/databases/<ENV_NAME>\` will get created.

    If the current directory is already initialized, you will get an error telling you the existing environment name.

    USAGE: heighliner init ENV_NAME
  EOS
end