Sha256: e57920d05c4fb3d81749bc17307d35b8eefc567b87109a7596d733ee782f179b

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'io/console'
require 'uffizzi'
require 'uffizzi/clients/api/api_client'

module Uffizzi
  class CLI::Config < Thor
    include ApiClient

    desc 'list', 'list'
    def list
      run('list')
    end

    desc 'get', 'get'
    def get(property)
      run('get', property)
    end

    desc 'set', 'set'
    def set(property, value)
      run('set', property, value)
    end

    desc 'delete', 'delete'
    def delete(property)
      run('delete', property)
    end

    private

    def run(command, property = nil, value = nil)
      case command
      when 'list'
        handle_list_command
      when 'get'
        handle_get_command(property)
      when 'set'
        handle_set_command(property, value)
      when 'delete'
        handle_delete_command(property)
      end
    end

    def handle_list_command
      ConfigFile.list
    end

    def handle_get_command(property)
      option = ConfigFile.read_option(property.to_sym)
      message = option.nil? ? "The option #{property} doesn't exist in config file" : option

      Uffizzi.ui.say(message)
    end

    def handle_set_command(property, value)
      ConfigFile.write_option(property.to_sym, value)
    end

    def handle_delete_command(property)
      ConfigFile.delete_option(property.to_sym)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uffizzi-cli-0.2.2 lib/uffizzi/cli/config.rb
uffizzi-cli-0.2.1 lib/uffizzi/cli/config.rb
uffizzi-cli-0.2.0 lib/uffizzi/cli/config.rb