Class: GitHooks::CLI::Config
Constant Summary collapse
- VALID_CONFIG_OPTIONS =
Repository::Config::OPTIONS.keys.freeze
Instance Method Summary collapse
-
#get(option) ⇒ Object
rubocop:disable MethodLength, AbcSize.
-
#list ⇒ Object
rubocop:disable AbcSize.
-
#set(option, value) ⇒ Object
rubocop:disable AbcSize.
-
#unset(option, value = nil) ⇒ Object
rubocop:disable AbcSize.
Instance Method Details
#get(option) ⇒ Object
rubocop:disable MethodLength, AbcSize
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 = !!['verbose'] GitHooks.debug = !!['debug'] repository = Repository.new(['repo']) config_data = repository.config.get(option, global: ['global']) config_data ||= 'not set' puts "Repository [#{repository.path.basename}]" Array(config_data).flatten.each do |value| puts " #{option} = #{value}" end end |
#list ⇒ Object
rubocop:disable AbcSize
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/githooks/cli/config.rb', line 77 def list # rubocop:disable AbcSize GitHooks.verbose = !!['verbose'] GitHooks.debug = !!['debug'] repository = Repository.new(['repo']) githooks = repository.config.list(global: ['global'])['githooks'] return unless githooks githooks.each do |path, data| key_size, value_size = data.keys.collect(&:size).maximum, data.values.collect(&:size).maximum 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) ⇒ Object
rubocop:disable AbcSize
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/githooks/cli/config.rb', line 51 def set(option, value) # rubocop:disable AbcSize GitHooks.verbose = !!['verbose'] GitHooks.debug = !!['debug'] Repository.new(['repo']).config.set( option, value, global: ['global'], overwrite: ['overwrite-all'] ).status.success? rescue ArgumentError => e puts e. end |
#unset(option, value = nil) ⇒ Object
rubocop:disable AbcSize
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/githooks/cli/config.rb', line 65 def unset(option, value = nil) # rubocop:disable AbcSize GitHooks.verbose = !!['verbose'] GitHooks.debug = !!['debug'] Repository.new(['repo']).config.unset( option, value, global: ['global'] ) rescue ArgumentError => e puts e. end |