acclaim 0.0.1.alpha2 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,8 +95,13 @@ module Acclaim
95
95
  # otherwise.
96
96
  def invoke(opts, args = [])
97
97
  opts.merge! parse_options!(args)
98
+ arg_separator = args.find { |arg| arg =~ Option::Parser::ARGUMENT_SEPARATOR }
99
+ separator_index = args.index arg_separator
98
100
  subcommands.find do |subcommand|
99
- subcommand.line == args.first
101
+ index = args.index subcommand.line
102
+ # If we have the subcommand AND the separator, then we have it if the
103
+ # subcommand is before the separator.
104
+ index and not separator_index or index < separator_index
100
105
  end.tap do |subcommand|
101
106
  if subcommand
102
107
  args.delete subcommand.line
@@ -6,6 +6,32 @@ module Acclaim
6
6
  # Parses arrays of strings and returns an Options instance containing data.
7
7
  class Parser
8
8
 
9
+ # Regular expression for any kind of option switch.
10
+ #
11
+ # Matches strings that begin with 1 or 2 dashes, are followed by at least
12
+ # one word character or number, and may be followed by any other word
13
+ # character, number or dash.
14
+ #
15
+ # Examples: -s, --long, -multiple, -1, --no-feature, --with_underscore,
16
+ # --_private_option, etc.
17
+ SWITCH = /^-{1,2}[\w\d]+[\w\d-]*$/
18
+
19
+ # Regular expression for multiple short options in a single "short"
20
+ # switch.
21
+ #
22
+ # Matches strings that begin with a single dash and are followed by 2 or
23
+ # more word characters, among which is the underscore but not the dash
24
+ # character.
25
+ #
26
+ # Examples: -xvf, -abc, -de_f
27
+ MULTIPLE_SHORT_SWITCHES = /^-\w{2,}$/
28
+
29
+ # Regular expression for the string that separates options and their
30
+ # parameters from arguments like filenames.
31
+ #
32
+ # Matches strings made up of 2 or more dashes.
33
+ ARGUMENT_SEPARATOR = /^-{2,}$/
34
+
9
35
  class Error < StandardError
10
36
 
11
37
  def self.raise_wrong_arg_number(actual, minimum, optional)
@@ -35,7 +61,7 @@ module Acclaim
35
61
 
36
62
  private
37
63
 
38
- # Argument array preprocessing. Does not touch
64
+ # Argument array preprocessing.
39
65
  def preprocess_argv!
40
66
  split_multiple_short_options!
41
67
  # TODO: normalize parameter formats?
@@ -46,18 +72,14 @@ module Acclaim
46
72
  end
47
73
 
48
74
  def split_multiple_short_options!
49
- argv.find_all { |arg| arg =~ /^-\w{2,}/ }.each do |multiples|
75
+ argv.find_all { |arg| arg =~ MULTIPLE_SHORT_SWITCHES }.each do |multiples|
50
76
  multiples_index = argv.index multiples
51
77
  argv.delete multiples
52
- options, *parameters = multiples.split /\s+/
53
- separated_options = options.sub!(/^-/, '').split(//).map! { |option| option.prepend '-' }
54
- separated_options.each_index do |option_index|
55
- argv.insert multiples_index + option_index, separated_options[option_index]
56
- end
57
- last_option_index = argv.index separated_options.last
58
- parameters.each_index do |parameter_index|
59
- argv.insert last_option_index + paramter_index + 1,
60
- parameters[parameter_index]
78
+ letters = multiples.sub!(/^-/, '').split(//)
79
+ letters.each { |letter| letter.prepend '-' }.tap do |options|
80
+ options.each_index do |option_index|
81
+ argv.insert multiples_index + option_index, options[option_index]
82
+ end
61
83
  end
62
84
  end
63
85
  end
@@ -84,7 +106,7 @@ module Acclaim
84
106
  values = []
85
107
  params.each do |param|
86
108
  case param
87
- when nil, /^-{1,2}/, /^-{2,}$/ then break
109
+ when nil, SWITCH, ARGUMENT_SEPARATOR then break
88
110
  else
89
111
  break if optional >= 0 and values.count >= minimum + optional
90
112
  values << param
@@ -4,7 +4,7 @@ module Acclaim
4
4
  MAJOR = 0
5
5
  MINOR = 0
6
6
  PATCH = 1
7
- BUILD = 'alpha2'
7
+ BUILD = nil
8
8
 
9
9
  STRING = [ MAJOR, MINOR, PATCH, BUILD ].compact.join '.'
10
10
 
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acclaim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha2
5
- prerelease: 6
4
+ version: 0.0.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matheus Afonso Martins Moreira
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-17 00:00:00.000000000 Z
12
+ date: 2011-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &7316860 !ruby/object:Gem::Requirement
16
+ requirement: &11364480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *7316860
24
+ version_requirements: *11364480
25
25
  description: Command-line option parser and command interface.
26
26
  email: matheus.a.m.moreira@gmail.com
27
27
  executables: []
@@ -57,9 +57,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
60
- - - ! '>'
60
+ - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
- version: 1.3.1
62
+ version: '0'
63
63
  requirements: []
64
64
  rubyforge_project:
65
65
  rubygems_version: 1.8.10