Class: Tweetwine::StartupConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/tweetwine/startup_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(supported_commands) ⇒ StartupConfig

Returns a new instance of StartupConfig.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/tweetwine/startup_config.rb', line 7

def initialize(supported_commands)
  @supported_commands = supported_commands.to_a
  raise ArgumentError, "Must give at least one supported command" if @supported_commands.empty?
  @options = {}
  @command = @supported_commands.first
  @args = []
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/tweetwine/startup_config.rb', line 5

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/tweetwine/startup_config.rb', line 5

def command
  @command
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/tweetwine/startup_config.rb', line 5

def options
  @options
end

#supported_commandsObject (readonly)

Returns the value of attribute supported_commands.



5
6
7
# File 'lib/tweetwine/startup_config.rb', line 5

def supported_commands
  @supported_commands
end

Instance Method Details

#parse(args = [], config_file = nil, &cmd_parser) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
# File 'lib/tweetwine/startup_config.rb', line 15

def parse(args = [], config_file = nil, &cmd_parser)
  options = parse_options(args, config_file, &cmd_parser)
  command = if args.empty? then @supported_commands.first else args.shift.to_sym end
  raise ArgumentError, "Unknown command" unless @supported_commands.include? command
  @options, @command, @args = options, command, args
  self
end