Class: Kdep::Commands::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/kdep/commands/config.rb

Overview

‘kdep config set <key> <value>` — writes a dotted key into ~/.kdep/config.yml. `kdep config get <key>` — reads a dotted key.

Currently used to seed Infisical settings:

kdep config set infisical.identity_id <uuid>
kdep config set infisical.host_api    https://dev-env.leadfy.xyz/api

Constant Summary collapse

SUBCOMMANDS =
%w[set get show].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(global_options:, command_options:, args:) ⇒ Config

Returns a new instance of Config.



20
21
22
23
24
25
# File 'lib/kdep/commands/config.rb', line 20

def initialize(global_options:, command_options:, args:)
  @global_options = global_options
  @command_options = command_options
  @args = args
  @ui = Kdep::UI.new
end

Class Method Details

.option_parserObject



14
15
16
17
18
# File 'lib/kdep/commands/config.rb', line 14

def self.option_parser
  OptionParser.new do |opts|
    opts.banner = "Usage: kdep config <set|get|show> [key] [value]"
  end
end

Instance Method Details

#executeObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kdep/commands/config.rb', line 27

def execute
  sub = @args.shift
  unless SUBCOMMANDS.include?(sub)
    @ui.error("Unknown subcommand: #{sub.inspect}. Available: #{SUBCOMMANDS.join(', ')}")
    exit 2
  end

  case sub
  when "set"
    key, value = @args[0], @args[1]
    unless key && value
      @ui.error("Usage: kdep config set <key> <value>")
      exit 2
    end
    path = Kdep::UserConfig.set(key, value)
    @ui.success("Set #{key} -> #{value} (#{path})")
  when "get"
    key = @args[0]
    unless key
      @ui.error("Usage: kdep config get <key>")
      exit 2
    end
    puts Kdep::UserConfig.get(*key.split("."))
  when "show"
    puts Kdep::UserConfig.load.to_yaml
  end
end