Class: SmilyCli::Commands::ConfigCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/smily_cli/commands/config_command.rb

Overview

Manage the on-disk config file and its profiles. Secrets are masked in any human-readable listing; the raw file (mode 0600) remains the source of truth. All subcommands accept --profile to target a specific profile.

Constant Summary collapse

SECRET_KEYS =
%w[token refresh_token client_secret mcp_token].freeze

Instance Method Summary collapse

Methods inherited from BaseCommand

exit_on_failure?

Instance Method Details

#get(key) ⇒ Object



65
66
67
68
# File 'lib/smily_cli/commands/config_command.rb', line 65

def get(key)
  value = config.profile(target_profile)[key]
  emit(value.nil? ? "" : value.to_s)
end

#initObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/smily_cli/commands/config_command.rb', line 32

def init
  name = target_profile
  token = options["token"] || prompt("Access token")
  base_url = options["base_url"] || prompt("Base URL [https://www.bookingsync.com]", default: Context::DEFAULT_BASE_URL)

  config.set("token", token, profile: name) unless token.to_s.empty?
  config.set("base_url", base_url, profile: name) unless base_url.to_s.empty?
  config.current_profile_name = name unless config.profile_names.length > 1 && options["profile"].nil?
  config.save
  success("Wrote profile #{name.inspect} to #{config.path}.")
end

#listObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/smily_cli/commands/config_command.rb', line 45

def list
  if config.profile_names.empty?
    notice("No profiles configured yet. Create one with `smily config init` or `smily config set`.")
    return
  end

  if context_output_json?
    emit(JSON.pretty_generate(masked_profiles))
    return
  end

  lines = config.profile_names.map do |name|
    marker = name == config.current_profile_name ? Color.green("* ") : "  "
    settings = masked_profile(name).map { |k, v| "#{k}=#{v}" }.join("  ")
    "#{marker}#{Color.bold(name)}  #{Color.dim(settings)}"
  end
  emit(lines.join("\n"))
end

#pathObject



18
19
20
# File 'lib/smily_cli/commands/config_command.rb', line 18

def path
  emit(config.path)
end

#remove(name) ⇒ Object



97
98
99
100
101
102
# File 'lib/smily_cli/commands/config_command.rb', line 97

def remove(name)
  confirm!("Delete profile #{name.inspect}?")
  config.delete_profile(name)
  config.save
  success("Removed profile #{name.inspect}.")
end

#set(key, value) ⇒ Object



71
72
73
74
75
76
# File 'lib/smily_cli/commands/config_command.rb', line 71

def set(key, value)
  warn_unknown_key(key)
  config.set(key, coerce(value), profile: target_profile)
  config.save
  success("Set #{key} on profile #{target_profile.inspect}.")
end

#unset(key) ⇒ Object



79
80
81
82
83
# File 'lib/smily_cli/commands/config_command.rb', line 79

def unset(key)
  config.unset(key, profile: target_profile)
  config.save
  success("Unset #{key} on profile #{target_profile.inspect}.")
end

#use(name) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/smily_cli/commands/config_command.rb', line 86

def use(name)
  unless config.profile?(name)
    notice(Color.yellow("Profile #{name.inspect} has no settings yet; selecting it anyway."))
  end
  config.current_profile_name = name
  config.save
  success("Default profile is now #{name.inspect}.")
end