Class: Dandelion::Command::Base

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

Direct Known Subclasses

Deploy, Init, Status

Constant Summary collapse

@@commands =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workspace, config, options = {}) ⇒ Base

Returns a new instance of Base.



65
66
67
68
69
# File 'lib/dandelion/command.rb', line 65

def initialize(workspace, config, options = {})
  @workspace = workspace
  @config = config
  @options = options
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



63
64
65
# File 'lib/dandelion/command.rb', line 63

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



63
64
65
# File 'lib/dandelion/command.rb', line 63

def options
  @options
end

#workspaceObject (readonly)

Returns the value of attribute workspace.



63
64
65
# File 'lib/dandelion/command.rb', line 63

def workspace
  @workspace
end

Class Method Details

.command(name) ⇒ Object



11
12
13
# File 'lib/dandelion/command.rb', line 11

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

.commandsObject



15
16
17
# File 'lib/dandelion/command.rb', line 15

def commands
  @@commands.keys
end

.lookup(name) ⇒ Object



19
20
21
22
# File 'lib/dandelion/command.rb', line 19

def lookup(name)
  raise InvalidCommandError.new(name) unless @@commands[name]
  @@commands[name]
end

.parser(options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
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
# File 'lib/dandelion/command.rb', line 24

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

    options[:version] = false
    opts.on('-v', '--version', 'Dispay the current version') do
      options[:version] = true
    end

    options[:help] = false
    opts.on('-h', '--help', 'Display this help info') do
      options[:help] = true
    end

    options[:repo] = nil
    opts.on('--repo=[REPO]', 'Use the given repository') do |repo|
      options[:repo] = repo
    end

    options[:config] = nil
    opts.on('--config=[CONFIG]', 'Use the given config file') do |config|
      options[:config] = config
    end

    opts.on('--log=[level]', 'Use the given log level (fatal, error, warn, info, debug)') do |level|
      levels = {
        fatal: Logger::FATAL,
        error: Logger::ERROR,
        warn: Logger::WARN,
        info: Logger::INFO,
        debug: Logger::DEBUG
      }

      Dandelion.logger.level = levels[level.to_sym]
    end
  end
end

Instance Method Details

#adapterObject



74
75
76
# File 'lib/dandelion/command.rb', line 74

def adapter
  workspace.adapter
end

#logObject



78
79
80
# File 'lib/dandelion/command.rb', line 78

def log
  Dandelion.logger
end

#setup(args) ⇒ Object



71
72
# File 'lib/dandelion/command.rb', line 71

def setup(args)
end