Class: Commander::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/commander/client.rb

Overview

CLI with options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
# File 'lib/commander/client.rb', line 10

def initialize(argv)
  @options = {}
  @argv = argv
  extract_options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/commander/client.rb', line 8

def options
  @options
end

Instance Method Details

#execute!Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/commander/client.rb', line 16

def execute!
  runner = Commander::Runner
  if @options[:force]
    puts 'Forcing ..'
    runner.new(@options).set_commander
  elsif @options[:status]
    puts 'Status output ..'
    runner.new(@options).show_status(@options[:status])
  elsif @options[:vacation]
    puts 'Setting specified user as <on vacation>'
    runner.new(@options).set_vacation_flag(@options[:vacation][0], @options[:vacation][1])
  elsif @options[:auto]
    puts 'Running with default settings..'
    runner.new(@options).set_commander
  elsif @options[:list]
    puts 'Display all Members: '
    runner.new(@options).list_all_members
  elsif @options[:setup]
    puts 'Running setup..'
    Commander::Setup.configure
  else
    puts @optparse
    exit
  end
end

#extract_optionsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/commander/client.rb', line 42

def extract_options
  @optparse = OptionParser.new do |opts|

    opts.banner = "Usage: commander [options] ..."

    @options[:vacation] = false
    opts.on( '-v', '--vacation name,bool', Array, '<NAME>,true/false(bool) comma is important' ) do |opt|
      @options[:vacation] = opt
    end

    @options[:force] = false
    opts.on( '-f', '--force name', 'Set COMM manually <NAME>' ) do |opt|
      @options[:force] = opt
    end

    @options[:status] = false
    opts.on( '-s', '--status name', 'Inspect history and status of <NAME>' ) do |opt|
      @options[:status] = opt
    end

    @options[:auto] = false
    opts.on( '-a', '--auto', 'Runs with default settings' ) do
      @options[:auto] = true
    end

    @options[:list] = false
    opts.on( '-l', '--list', 'Lists all available Members.' ) do |opt|
      @options[:list] = opt
    end

    @options[:setup] = false
    opts.on( '-x' ,'--setup', 'Runs setup for your environment.' ) do |opt|
      @options[:setup] = opt
    end

    opts.on( '-h', '--help', 'Display this screen' ) do
      puts opts
      exit
    end

    opts.on( '-u', '--version', 'Print programs version' ) do
      puts Commander::VERSION
      exit
    end
  end
  @optparse.parse(@argv)
end