Sha256: f455f1a25d15f5ac1858264d31380c423d80e5c0c85c7a399376a1ce32c7aad4

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module Ona

  class Cli

    FRINED_ACTIONS = %q{deploy setup}
    LONE_ACTIONS = %q{list ls}

    def initialize(stack)
      @stack = stack
    end

    def selected_servers string
      @stack.find_all(*string.scan(/\d+/).map { |id| id.to_i })
    end

    def unknown_command
      puts 'Unknown command.'
      help
    end

    def help
      puts "
      Ona -- Deployment simplified.

      help          # show this help

      ls            # short list for available servers
      list          # detailed list for available servers

      deploy 1      # Deploy a specific server
      deploy 1 2 3  # Deploy servers with ids: 1 2 and 3

      setup 1       # Upload ssh-keys and bootstrap server
      setup 1 2 3   # Setup servers with ids: 1 2 and 3

      quit          # Setup servers with ids: 1 2 and 3

      "
    end

    def list string
      selected_servers(string).each do |server|
        puts server.to_s
      end
    end

    def ls
      @stack.to_a.each do |server|
        puts server.to_short_s
      end
    end

    def deploy string
      selected_servers(string).each do |server|
        system server.deploy
      end
    end

    def setup string
      install_ssh_keys string
      bootstrap string
    end

    protected

    def bootstrap string
      selected_servers(string).each do |server|
        system server.bootstrap
      end
    end

    def install_ssh_keys string
      selected_servers(string).each do |server|
        system server.setup_ssh
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ona-0.1.0 lib/ona_cli.rb
ona-0.0.2 lib/ona_cli.rb