Class: MGit::AddCommand

Inherits:
Command show all
Defined in:
lib/mgit/commands/add.rb

Instance Method Summary collapse

Methods inherited from Command

execute, instance_each, list, register_alias, register_command

Methods included from Output

#perror, #pinfo, #ptable, #pwarn

Instance Method Details

#arityObject



13
14
15
# File 'lib/mgit/commands/add.rb', line 13

def arity
  [1, 2]
end

#descriptionObject



21
22
23
# File 'lib/mgit/commands/add.rb', line 21

def description
  'add a repository to mgit'
end

#execute(args) ⇒ Object

Raises:



3
4
5
6
7
8
9
10
11
# File 'lib/mgit/commands/add.rb', line 3

def execute(args)
  path = File.expand_path(args[0])
  raise CommandUsageError.new('First argument must be a path to a git repository.', self) unless is_git_dir?(path)

  name = (args.size == 2) ? args[1] : (ask('Name of the repository? ') { |q| q.default = File.basename(path) })
  raise CommandUsageError.new("Repository named #{name} already exists with different path.", self) unless is_new_or_same?(name, path)
  
  Registry.add(name, path)
end

#usageObject



17
18
19
# File 'lib/mgit/commands/add.rb', line 17

def usage
  'add <path_to_git_repository> [name]'
end