Class: Winnie::Commands::Base

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

Direct Known Subclasses

App, Auth, Help

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#ask, #confirm, #display, #display_columns, #error, #line

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



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

def initialize(*args)
  @args = args.flatten
  extract_options(@args)
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



4
5
6
# File 'lib/winnie/commands/base.rb', line 4

def api_key
  @api_key
end

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/winnie/commands/base.rb', line 4

def args
  @args
end

#winnieObject (readonly)

Returns the value of attribute winnie.



4
5
6
# File 'lib/winnie/commands/base.rb', line 4

def winnie
  @winnie
end

Instance Method Details

#code_nameObject



27
28
29
# File 'lib/winnie/commands/base.rb', line 27

def code_name
  @code_name || raise(ApplicationNotSpecyfiedException.new)
end

#config_pathObject



36
37
38
# File 'lib/winnie/commands/base.rb', line 36

def config_path
  File.expand_path('~/.winnie')
end

#extract_options(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/winnie/commands/base.rb', line 13

def extract_options(args)
  return if args.empty?

  OptionParser.new do |opts|
    opts.on("-a", "--app [CODE-NAME]", :text, "Run for given application") do |a|
      @code_name = a
    end

    opts.on("-k", "--api-key [API-KEY]", :text, "Authorize command for given api key") do |k|
      @api_key = k
    end
  end.parse!(@args)
end