Class: Dandelion::Command::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dandelion/command.rb

Direct Known Subclasses

Deploy, Status

Constant Summary collapse

@@commands =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:



75
76
77
78
79
80
81
# File 'lib/dandelion/command.rb', line 75

def initialize(options)
  @options = options        
  @config = YAML.load_file(@options[:config])
  @repo = Git::Repo.new(@options[:repo])
  
  yield(self) if block_given?
end

Class Method Details

.command(name) ⇒ Object



17
18
19
# File 'lib/dandelion/command.rb', line 17

def command(name)
  @@commands[name] = self
end

.commandsObject



27
28
29
# File 'lib/dandelion/command.rb', line 27

def commands
  @@commands.keys
end

.create(name) ⇒ Object



21
22
23
24
25
# File 'lib/dandelion/command.rb', line 21

def create(name)
  require_commands
  raise InvalidCommandError unless @@commands.include?(name)
  @@commands[name]
end

.parser(options) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dandelion/command.rb', line 35

def parser(options)
  OptionParser.new do |opts|
    opts.banner = 'Usage: dandelion [options] <command> [<args>]'

    opts.on('-v', '--version', 'Display the current version') do
      puts "Dandelion #{Dandelion::VERSION}"
      exit
    end

    opts.on('-h', '--help', 'Display this screen') do
      require_commands
      puts opts
      puts "\nAvailable commands:"
      puts commands.map { |name| "    #{name}" }.join("\n")
      exit
    end

    options[:repo] = closest_repo(File.expand_path('.'))
    opts.on('--repo=[REPO]', 'Use the given repository') do |repo|
      options[:repo] = File.expand_path(repo)
    end
    
    options[:config] = nil
    opts.on('--config=[CONFIG]', 'Use the given configuration file') do |config|
      options[:config] = File.expand_path(config)
    end
  end
end

.require_commandsObject



31
32
33
# File 'lib/dandelion/command.rb', line 31

def require_commands
  Dir.glob(File.join(File.dirname(__FILE__), 'command', '*.rb')) { |file| require file }
end