Class: DeploYML::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/deployml/cli.rb

Overview

The command-line interface to DeploYML using Thor.

Instance Method Summary collapse

Instance Method Details

#configObject

Configures the server for the specified environment.



130
131
132
133
134
135
136
# File 'lib/deployml/cli.rb', line 130

def config
  status 'Configuring ...'

  project.config!(options[:environment])

  status 'Configured'
end

#deployObject

Cold-deploys into the specified environment.



194
195
196
197
198
199
200
# File 'lib/deployml/cli.rb', line 194

def deploy
  status 'Deploying ...'

  project.deploy!(options[:environment])

  status 'Deployed'
end

#environmentEnvironment (protected)

The selected environment.

Returns:

  • (Environment)

    A deployment environment of the project.

Since:

  • 0.3.0



266
267
268
# File 'lib/deployml/cli.rb', line 266

def environment
  project.environment(options[:environment])
end

#exec(command) ⇒ Object

Executes a command in the specified environment.

Parameters:

  • command (String)

    The full command to execute.



26
27
28
# File 'lib/deployml/cli.rb', line 26

def exec(command)
  environment.exec(command)
end

#find_rootPathname (protected)

Finds the root of the project, starting at the current working directory and ascending upwards.

Returns:

  • (Pathname)

    The root of the project.

Since:

  • 0.3.0



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/deployml/cli.rb', line 229

def find_root
  Pathname.pwd.ascend do |root|
    config_dir = root.join(Project::CONFIG_DIR)

    if config_dir.directory?
      config_file = config_dir.join(Project::CONFIG_FILE)
      return root if config_file.file?

      environments_dir = config_dir.join(Project::ENVIRONMENTS_DIR)
      return root if environments_dir.directory?
    end
  end

  shell.say "Could not find '#{Project::CONFIG_FILE}' in any parent directories", :red
  exit -1
end

#installObject

Installs any needed dependencies in the specified environment.



98
99
100
101
102
103
104
# File 'lib/deployml/cli.rb', line 98

def install
  status 'Installing ...'

  project.install!(options[:environment])

  status 'Installed'
end

#migrateObject

Migrates the database for the specified environment.



114
115
116
117
118
119
120
# File 'lib/deployml/cli.rb', line 114

def migrate
  status 'Migrating ...'

  project.migrate!(options[:environment])

  status 'Migrated'
end

#projectProject (protected)

The project.

Returns:

  • (Project)

    The project object.

Since:

  • 0.3.0



254
255
256
# File 'lib/deployml/cli.rb', line 254

def project
  @project ||= Project.new(find_root)
end

#rake(task) ⇒ Object

Invokes a rake task in the specified environment.

Parameters:

  • task (String)

    The name of the rake task.



42
43
44
# File 'lib/deployml/cli.rb', line 42

def rake(task)
  environment.rake(task,*(options[:args]))
end

#redeployObject

Redeploys into the specified environment.



210
211
212
213
214
215
216
# File 'lib/deployml/cli.rb', line 210

def redeploy
  status 'Redeploying ...'

  project.redeploy!(options[:environment])

  status 'Redeployed'
end

#restartObject

Restarts the server in the specified environment.



178
179
180
181
182
183
184
# File 'lib/deployml/cli.rb', line 178

def restart
  status 'Restarting ...'

  project.restart!(options[:environment])

  status 'Restarted'
end

#setupObject

Sets up the specified environment.



66
67
68
69
70
71
72
# File 'lib/deployml/cli.rb', line 66

def setup
  status 'Setting up ...'

  project.setup!(options[:environment])

  status 'Setup'
end

#sshObject

Starts an SSH session with the specified environment.



54
55
56
# File 'lib/deployml/cli.rb', line 54

def ssh
  environment.ssh
end

#startObject

Starts the server in the specified environment.



146
147
148
149
150
151
152
# File 'lib/deployml/cli.rb', line 146

def start
  status 'Starting ...'

  project.start!(options[:environment])

  status 'Started'
end

#status(message) ⇒ Object (protected)

Prints a status message.

Parameters:

  • message (String)

    The message to print.



276
277
278
# File 'lib/deployml/cli.rb', line 276

def status(message)
  shell.say_status "[#{options[:environment]}]", message
end

#stopObject

Stops the server in the specified environment.



162
163
164
165
166
167
168
# File 'lib/deployml/cli.rb', line 162

def stop
  status 'Stopping ...'

  project.stop!(options[:environment])

  status 'Stopped'
end

#updateObject

Updates the deployment repository of the specified environment.



82
83
84
85
86
87
88
# File 'lib/deployml/cli.rb', line 82

def update
  status 'Updating'

  project.update!(options[:environment])

  status 'Updated'
end