Sha256: 75c3aa75fb8f17832f74ae3e4f9df72b666bd2ba58e2e13eaba88c427326567a

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

module LitmusPaper
  module CLI
    class Admin
      def self.commands
        {
          "list" => LitmusPaper::CLI::Admin::List,
          "force" => LitmusPaper::CLI::Admin::Force,
          "status" => LitmusPaper::CLI::Admin::Status
        }
      end

      def run(argv = ARGV)
        command_name = argv.shift

        if command = Admin.commands[command_name]
          options = {}
          request = command.build_request(options, argv)
          _litmus_request(options[:host], options[:port], request)
        else
          _display_help
        end
      end

      def _display_help
        puts "Litmus Paper CLI v#{LitmusPaper::VERSION}\n\n"
        puts "Commands:\n"
        Admin.commands.keys.sort.each do |name|
          puts "  %-8s %s" % [name, Admin.commands[name].description]
        end
        puts "\nSee 'litmusctl <command> --help' for more information on a specific command"
      end

      def _litmus_request(host, port, request)
        begin
          http = Net::HTTP.start(host, port)
          response = http.request(request)

          puts response.body
          case response
          when Net::HTTPSuccess then exit 0
          when Net::HTTPClientError then exit 2
          else exit 1
          end
        rescue Errno::ECONNREFUSED => e
          puts "Unable to connect to litmus on #{host}:#{port}: #{e.message}"
          exit 1
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
litmus_paper-0.6.2 lib/litmus_paper/cli/admin.rb
litmus_paper-0.6.1 lib/litmus_paper/cli/admin.rb
litmus_paper-0.6.0 lib/litmus_paper/cli/admin.rb
litmus_paper-0.5.0 lib/litmus_paper/cli/admin.rb
litmus_paper-0.4.0 lib/litmus_paper/cli/admin.rb