Class: Sunshine::AddCommand

Inherits:
ListCommand show all
Defined in:
lib/commands/add.rb

Overview

Registers a path as a sunshine application for control via sunshine.

Usage: sunshine add [options] app_path [more paths…]

Arguments:

app_path    Path to the application to add.
            A name may be assigned to the app by specifying name:path.
            By default: name = File.basename app_path

Options:

-f, --format FORMAT        Set the output format (txt, yml, json)
-u, --user USER            User to use for remote login. Use with -r.
-r, --remote svr1,svr2     Run on one or more remote servers.
-v, --verbose              Run in verbose mode.

Instance Attribute Summary

Attributes inherited from ListCommand

#app_list, #shell

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ListCommand

build_response, #details, #each_app, exec_each_server, #exist?, #initialize, json_format, load_list, #response_for_each, save_list, #status, #status_after_command, txt_format, yml_format

Methods inherited from DefaultCommand

build_response, copy_middleware, copy_rakefile, opt_parser, parse_remote_args

Constructor Details

This class inherits a constructor from Sunshine::ListCommand

Class Method Details

.exec(names, config) ⇒ Object

Takes an array and a hash, runs the command and returns:

true: success
false: failed
exitcode:
  code == 0: success
  code != 0: failed

and optionally an accompanying message.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/commands/add.rb', line 30

def self.exec names, config
  apps_hash  = parse_app_paths(*names)

  output = exec_each_server config do |shell|
    server_command = new(shell)
    results        = server_command.add apps_hash

    self.save_list server_command.app_list, shell

    results
  end

  return output
end

.parse_app_paths(*app_paths) ⇒ Object

Takes an array of app path definitions and returns a hash:

parse_app_paths "myapp:/path/to/app", "/path/to/otherapp"
#=> {'myapp' => '/path/to/app', 'otherapp' => '/path/to/otherapp'}


51
52
53
54
55
56
57
58
59
60
# File 'lib/commands/add.rb', line 51

def self.parse_app_paths(*app_paths)
  apps_hash = {}
  app_paths.each do |path|
    name, path = path.split(":") if path.include?(":")
    name ||= File.basename path

    apps_hash[name] = path
  end
  apps_hash
end

.parse_args(argv) ⇒ Object

Parses the argv passed to the command



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/commands/add.rb', line 81

def self.parse_args argv

  parse_remote_args(argv) do |opt, options|
    opt.banner = <<-EOF

Usage: #{opt.program_name} add [options] app_path [more paths...]

Arguments:
app_path      Path to the application to add.
              A name may be assigned to the app by specifying name:app_path.
              By default: name = File.basename app_path
    EOF
  end
end

Instance Method Details

#add(apps_hash) ⇒ Object

Add a registered app on a given deploy server



66
67
68
69
70
71
72
73
74
75
# File 'lib/commands/add.rb', line 66

def add apps_hash
  response_for_each(*apps_hash.keys) do |name|
    path = apps_hash[name]
    test_dir = @shell.call("test -d #{path}") rescue false

    raise "'#{path}' is not a directory." unless test_dir

    @app_list[name] = path
  end
end