Class: Kaiser::Cmds::Init
- Inherits:
-
Kaiser::Cli
- Object
- Kaiser::Cli
- Kaiser::Cmds::Init
- Defined in:
- lib/kaiser/cmds/init.rb
Instance Attribute Summary
Attributes inherited from Kaiser::Cli
Instance Method Summary collapse
- #execute(_opts) ⇒ Object
- #init_config_for_env(name) ⇒ Object
- #largest_port ⇒ Object
-
#usage ⇒ Object
TODO: Add explanation for the Already initialized error.
Methods inherited from Kaiser::Cli
all_subcommands_usage, #define_options, #initialize, register, run_command, #set_config, #start_services, #stop_app, #stop_services
Methods included from Kaiser::CliOptions
Constructor Details
This class inherits a constructor from Kaiser::Cli
Instance Method Details
#execute(_opts) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/kaiser/cmds/init.rb', line 15 def execute(_opts) return Optimist.die "Already initialized as #{envname}" 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
25 26 27 28 29 30 31 32 |
# File 'lib/kaiser/cmds/init.rb', line 25 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_port ⇒ Object
34 35 36 |
# File 'lib/kaiser/cmds/init.rb', line 34 def largest_port Config.config[:largest_port] end |
#usage ⇒ Object
TODO: Add explanation for the Already initialized error.
7 8 9 10 11 12 13 |
# File 'lib/kaiser/cmds/init.rb', line 7 def usage <<~EOS Initializes a Kaiser environment and assigns ports for it in \`~/.kaiser/.config.yml\`. When running \`kaiser up\` later the directory \`~/.kaiser/databases/<ENV_NAME>\` will get created. USAGE: kaiser init ENV_NAME EOS end |