class GitHooks::CLI::Config

Constants

VALID_CONFIG_OPTIONS

Public Instance Methods

get(option) click to toggle source
# File lib/githooks/cli/config.rb, line 25
def get(option) # rubocop:disable MethodLength, AbcSize
  unless VALID_CONFIG_OPTIONS.include? option
    puts "Invalid option '#{option}': expected one of #{VALID_CONFIG_OPTIONS.join(', ')}"
    return 1
  end

  GitHooks.verbose = !!options['verbose']
  GitHooks.debug   = !!options['debug']

  repository  = Repository.new(options['repo'])
  config_data = repository.config.get(option, global: options['global'])
  config_data ||= 'not set'

  puts "Repository [#{repository.path.basename}]"
  Array(config_data).flatten.each do |value|
    puts "  #{option} = #{value}"
  end
end
list() click to toggle source
# File lib/githooks/cli/config.rb, line 77
def list # rubocop:disable AbcSize
  GitHooks.verbose = !!options['verbose']
  GitHooks.debug   = !!options['debug']

  repository = Repository.new(options['repo'])
  githooks   = repository.config.list(global: options['global'])['githooks']
  return unless githooks

  githooks.each do |path, data|
    key_size, value_size = data.keys.collect(&:size).max, data.values.collect(&:size).max
    display_format = "    %-#{key_size}s = %-#{value_size}s\n"

    puts "Repository [#{File.basename(path)}]"
    printf display_format, 'Repo Path', path

    data.each { |key, value|
      Array(value).flatten.each do |v|
        printf display_format, key.tr('-', ' ').titleize, v
      end
    }
  end
end
set(option, value) click to toggle source
# File lib/githooks/cli/config.rb, line 51
def set(option, value) # rubocop:disable AbcSize
  GitHooks.verbose = !!options['verbose']
  GitHooks.debug   = !!options['debug']

  Repository.new(options['repo']).config.set(
    option, value,
    global:    options['global'],
    overwrite: options['overwrite-all']
  ).status.success?
rescue ArgumentError => e
  puts e.message
end
unset(option, value = nil) click to toggle source
# File lib/githooks/cli/config.rb, line 65
def unset(option, value = nil) # rubocop:disable AbcSize
  GitHooks.verbose = !!options['verbose']
  GitHooks.debug   = !!options['debug']

  Repository.new(options['repo']).config.unset(
    option, value, global: options['global']
  )
rescue ArgumentError => e
  puts e.message
end