class KBSecret::Config

Global and per-session configuration for kbsecret.

Constants

COMMAND_CONFIG_FILE

The command configuration file. @api private

CONFIG_DIR

The configuration directory. @api private

CONFIG_FACETS

Configuration facets used for method generation. @api private

CONFIG_FILE

The configuration file. @api private

CUSTOM_TYPES_DIR

The directory searched for custom record types. @api private

DEFAULT_CONFIG

configuration defaults @api private

DEFAULT_GENERATOR

The default generator configuration.

DEFAULT_SESSION

The default session configuration.

Public Class Methods

[](key) click to toggle source

Retrieve a configured value. @param key [String] the configuration key to retrieve @return [Object] the corresponding configuration

# File lib/kbsecret/config.rb, line 95
def self.[](key)
  @config[key]
end
command(cmd) click to toggle source

Fetch the configuration for a `kbsecret` command. @param cmd [String] the short name of the command @return [Hash, nil] the command's configuration @example

# retrieves the config for `kbsecret-list`
Config.command("list") # => { "args" => "...",  }
# File lib/kbsecret/config.rb, line 105
def self.command(cmd)
  @command_config[cmd]
end
command_args(cmd) click to toggle source

Fetch the configured default arguments for a `kbsecret` command. @param cmd [String] the short name of the command @return [Array] the command's default arguments @note Default arguments are split according to normal shell splitting rules. @example

Config.command_args("list") # => ["--show-all"]
# File lib/kbsecret/config.rb, line 115
def self.command_args(cmd)
  @command_config.dig(cmd, "args")&.shellsplit || []
end
load!() click to toggle source

Reads the user's configuration files from disk, introducing default values as necessary. @return [void] @api private

# File lib/kbsecret/config.rb, line 68
def self.load!
  user_config = if File.exist?(CONFIG_FILE)
                  YAML.load_file(CONFIG_FILE)
                else
                  DEFAULT_CONFIG
                end

  @command_config = if File.exist?(COMMAND_CONFIG_FILE)
                      INIH.load(COMMAND_CONFIG_FILE)
                    else
                      {}
                    end

  @config = DEFAULT_CONFIG.merge(user_config)
  @config[:sessions].merge!(DEFAULT_SESSION)
  @config[:generators].merge!(DEFAULT_GENERATOR)
end
sync!() click to toggle source

Writes the user's configuration to disk. @return [void]

# File lib/kbsecret/config.rb, line 88
def self.sync!
  File.write(CONFIG_FILE, @config.to_yaml)
end
unalias_command(acmd) click to toggle source

Attempt to resolve an alias into a `kbsecret` command. @param acmd [String] the command alias @return [String] the `kbsecret` command, or `acmd` if the alias does not exist @example

Config.unalias_command("l") # => "list"
Config.unalias_command("madeup") # => "madeup"
# File lib/kbsecret/config.rb, line 125
def self.unalias_command(acmd)
  @command_config.each do |cmd, conf|
    aliases = conf["aliases"]&.split || []
    return cmd if aliases.include?(acmd)
  end

  acmd
end