Class: Pigtail::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/pigtail/command_line.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CommandLine

Returns a new instance of CommandLine.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pigtail/command_line.rb', line 10

def initialize(options={})
  @options                = options
  @options[:file]       ||= 'config/pigtail.rb'
  @options[:identifier] ||= default_identifier
  # @options[:cut]        ||= 0

  if !File.exists?(@options[:file]) && @options[:clear].nil?
    warn("[fail] Can't find file: #{@options[:file]}")
    exit(1)
  end

  # if [@options[:update], @options[:write], @options[:clear]].compact.length > 1
  #   warn("[fail] Can only update, write or clear. Choose one.")
  #   exit(1)
  # end

  # unless @options[:cut].to_s =~ /[0-9]*/
  #   warn("[fail] Can't cut negative lines from the pigtail_config #{options[:cut]}")
  #   exit(1)
  # end
  # @options[:cut] = @options[:cut].to_i
end

Class Method Details

.execute(options = {}) ⇒ Object



6
7
8
# File 'lib/pigtail/command_line.rb', line 6

def self.execute(options={})
  new(options).run
end

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pigtail/command_line.rb', line 33

def run
  # if @options[:update] || @options[:clear]
  #   write_pigtail_config(updated_pigtail_config)
  # elsif @options[:write]
  if @options[:write]
    write_pigtail_config(pigtail_configs)
  else
    puts Pigtail.configs(@options)
    puts "## [message] Above is your pigtail_config file converted to config syntax; your pigtail_config file was not updated."
    puts "## [message] Run `pigtail --help' for more options."
    exit(0)
  end
end