Sha256: ae25f802e824bd627de8d6890eeb6553637f943ce48514524565357be3827237

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require 'thor'

module Kuberun
  # Handle the application command line parsing
  # and the dispatch to various command objects
  #
  # @api public
  class CLI < Thor
    DEFAULT_OPTIONS_FOR_KUBECTL_OPTIONS = { type: :string, default: '', desc: 'See kubectl options' }.freeze
    BASE_KUBECTL_OPTIONS = {
      'certificate-authority': {},
      'client-certificate': {},
      'client-key': {},
      'cluster': {},
      'context': {},
      'insecure-skip-tls-verify': {},
      'kubeconfig': {},
      'namespace': { aliases: :'-n' },
      'token': {},
      'v': { type: :numeric, default: 0, desc: 'Log level passed to kubectl' }
    }.freeze
    BASE_KUBECTL_OPTIONS.each do |option_name, hash|
      class_option option_name, DEFAULT_OPTIONS_FOR_KUBECTL_OPTIONS.merge(hash)
    end
    class_option :debug, type: :boolean, default: false, desc: 'Debug logging'

    # Error raised by this runner
    Error = Class.new(StandardError)

    desc 'version', 'kuberun version'
    def version
      require_relative 'version'
      puts "v#{Kuberun::VERSION}"
    end
    map %w[--version -v] => :version

    desc 'run_pod DEPLOYMENT_NAME', 'Starts pod for command'
    method_option :help, aliases: '-h', type: :boolean,
                         desc: 'Display usage information'
    def run_pod(deployment_name)
      if options[:help]
        invoke :help, ['run_pod']
      else
        require_relative 'commands/run_pod'
        Kuberun::Commands::RunPod.new(deployment_name, options).execute
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kuberun-0.2.1 lib/kuberun/cli.rb
kuberun-0.2.0 lib/kuberun/cli.rb
kuberun-0.1.4 lib/kuberun/cli.rb
kuberun-0.1.2 lib/kuberun/cli.rb
kuberun-0.1.1 lib/kuberun/cli.rb