Class: MGit::ConfigCommand

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

Instance Method Summary collapse

Methods inherited from Command

#check_arity, create, execute, instance_each, list, load_commands, register_alias, register_command, require_commands_from_directory

Methods included from Output

#perror, #pinfo, #psystem, #ptable, #pwarn

Instance Method Details

#arityObject



26
27
28
# File 'lib/mgit/commands/config.rb', line 26

def arity
  [0, 2]
end

#descriptionObject



34
35
36
# File 'lib/mgit/commands/config.rb', line 34

def description
  'configure MGit'
end

#execute(args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mgit/commands/config.rb', line 3

def execute(args)
  if args.size == 0
    t = []
    Configuration.each { |k, v| t << [k.to_s, v] }
    ptable t
  else
    key = args[0]

    if args.size == 1
      psystem Configuration.send(key.to_sym).to_s
    else
      key = args[0]
      value = args[1]

      begin
        Configuration.set(key, value)
      rescue ConfigurationError => e
        raise CommandUsageError.new(e.to_s, self)
      end
    end
  end
end

#usageObject



30
31
32
# File 'lib/mgit/commands/config.rb', line 30

def usage
  'config <key> <value>'
end