Class: DbAgile::Command::Repo::Create

Inherits:
DbAgile::Command show all
Defined in:
lib/dbagile/command/repo/create.rb

Overview

Create a fresh dbagile repository in a specific directory

Usage: dba #DbAgile::Command#command_name [DIR]

This commands creates a dbagile repository in a directory. When none is specified, it will create a repository under ‘dbagile’ in the current folder.

Constant Summary

Constants inherited from DbAgile::Command

CATEGORIES, CATEGORY_NAMES

Instance Attribute Summary collapse

Attributes inherited from DbAgile::Command

#environment

Attributes included from ClassMethods

#description, #summary, #usage

Instance Method Summary collapse

Methods inherited from DbAgile::Command

#category, #check_command, #command_name, #description, #initialize, #options, #run, #set_default_options, #show_help, #summary, #unsecure_run, #usage

Methods included from ClassMethods

#build_command_options, #build_me, #category, #command_for, #command_name, #command_name_of, #each_subclass, #inherited, #ruby_method_for, #subclasses

Methods included from DbAgile::Command::Robust

#ambigous_argument_list!, #assumption_error!, #bad_argument_list!, #has_command!, #is_in!, #valid_argument_list!, #valid_read_file!

Methods included from DbAgile::Core::IO::Robustness

#has_database!, #valid_database_name!, #valid_database_uri!, #valid_schema_files!

Constructor Details

This class inherits a constructor from DbAgile::Command

Instance Attribute Details

#forceObject

Force repository creation?



20
21
22
# File 'lib/dbagile/command/repo/create.rb', line 20

def force
  @force
end

#whereObject

Where does the repository must be create?



17
18
19
# File 'lib/dbagile/command/repo/create.rb', line 17

def where
  @where
end

Instance Method Details

#add_options(opt) ⇒ Object

Contribute to options



23
24
25
26
27
28
29
30
31
# File 'lib/dbagile/command/repo/create.rb', line 23

def add_options(opt)
  self.force = false
  opt.separator nil
  opt.separator "Options:"
  opt.on("--force", 
         "Force creation of the repository, removing the folder if it already exists") do |value|
    self.force = true
  end
end

#execute_commandObject

Executes the command



43
44
45
46
47
48
49
# File 'lib/dbagile/command/repo/create.rb', line 43

def execute_command
  if File::exists?(self.where) and self.force
    FileUtils::rm_rf(self.where)
  end
  DbAgile::Core::Repository::create!(self.where)
  say("Repository successfully created!", :magenta)
end

#normalize_pending_arguments(arguments) ⇒ Object

Normalizes the pending arguments



34
35
36
37
38
39
40
# File 'lib/dbagile/command/repo/create.rb', line 34

def normalize_pending_arguments(arguments)
  if arguments.empty?
    self.where = "dbagile"
  else
    self.where = valid_argument_list!(arguments, String)
  end
end