Class: Proviso::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers, PluginInterface
Defined in:
lib/proviso/commands/base.rb

Direct Known Subclasses

Config, Hello, Plugins

Constant Summary

Constants included from Helpers

Helpers::CONFIG_FILE, Helpers::PROVISO_PATH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PluginInterface

#applications, #base_command, #command, included, #selected_application

Methods included from Helpers

#home_directory, #running_on_a_mac?, #running_on_windows?, #yaml_file

Constructor Details

#initialize(args) ⇒ Base

Returns a new instance of Base.



10
11
12
# File 'lib/proviso/commands/base.rb', line 10

def initialize(args)
  @args = args
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



8
9
10
# File 'lib/proviso/commands/base.rb', line 8

def args
  @args
end

Instance Method Details

#display(msg, newline = true) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/proviso/commands/base.rb', line 14

def display(msg, newline=true)
  if newline
    puts(msg)
  else
    print(msg)
    STDOUT.flush
  end
end

#error(msg) ⇒ Object



23
24
25
# File 'lib/proviso/commands/base.rb', line 23

def error(msg)
  Proviso::Command.error(msg)
end

#extract_option(options, default = true) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/proviso/commands/base.rb', line 27

def extract_option(options, default=true)
  values = options.is_a?(Array) ? options : [options]
  return unless opt_index = args.select { |a| values.include? a }.first
  opt_position = args.index(opt_index) + 1
  if args.size > opt_position && opt_value = args[opt_position]
    if opt_value.include?('--')
      opt_value = nil
    else
      args.delete_at(opt_position)
    end
  end
  opt_value ||= default
  args.delete(opt_index)
  block_given? ? yield(opt_value) : opt_value
end