frag 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.2.2 2012-08-11
2
+
3
+ * Gracefully exit if an invalid option is given.
4
+
1
5
  == 0.2.1 2012-08-11
2
6
 
3
7
  * Gracefully exit if file is not writable.
@@ -12,7 +12,11 @@ module Frag
12
12
 
13
13
  @state = State.new('frag:', 'frag end', '#', '', nil, nil)
14
14
 
15
- parser.parse!(args)
15
+ begin
16
+ parser.parse!(args)
17
+ rescue OptionParser::InvalidOption => e
18
+ return error e.message
19
+ end
16
20
  args.size > 0 || @version_printed or
17
21
  return error "no files given"
18
22
 
@@ -100,7 +104,7 @@ module Frag
100
104
  def parse_subconfig!(args)
101
105
  self.parsing_subconfig = true
102
106
  # OptionParser will error on an argument like like "-->".
103
- if args.last =~ /\A--?(?:\W|\z)/
107
+ if args.last =~ /\A--?(?:[^0-9a-zA-Z]|\z)/
104
108
  last_arg = args.pop
105
109
  parse!(args)
106
110
  args << last_arg
@@ -164,7 +168,11 @@ module Frag
164
168
  output.puts line
165
169
  when /\A\s*(?:(\S+)\s*)?\$frag-config:\s*(.*)$/
166
170
  args = Shellwords.shellsplit($2)
167
- parser.parse_subconfig!(args)
171
+ begin
172
+ parser.parse_subconfig!(args)
173
+ rescue OptionParser::InvalidOption => e
174
+ return error "#{input.lineno}: #{e.message}"
175
+ end
168
176
  args.size <= 1 or
169
177
  return error "#{input.lineno}: unexpected argument(s): #{args[0..-2].join(' ')}"
170
178
  @state.leader = $1 || ''
@@ -1,5 +1,5 @@
1
1
  module Frag
2
- VERSION = [0, 2, 1]
2
+ VERSION = [0, 2, 2]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
@@ -371,6 +371,7 @@ describe Frag::App do
371
371
  |# $frag-config: --leader %
372
372
  EOS
373
373
  frag('input').must_equal 0
374
+ output.string.must_equal ''
374
375
  error.string.must_equal "warning: -l / --leader is unnecessary in $frag-config line\n"
375
376
  end
376
377
 
@@ -379,6 +380,7 @@ describe Frag::App do
379
380
  |# $frag-config: --trailer %
380
381
  EOS
381
382
  frag('input').must_equal 0
383
+ output.string.must_equal ''
382
384
  error.string.must_equal "warning: -t / --trailer is unnecessary in $frag-config line\n"
383
385
  end
384
386
 
@@ -502,12 +504,22 @@ describe Frag::App do
502
504
  EOS
503
505
  end
504
506
 
507
+ it "errors if there is an invalid option" do
508
+ write_file 'input', <<-EOS.demargin
509
+ |# $frag-config: --invalid x
510
+ EOS
511
+ frag('input').must_equal 1
512
+ output.string.must_equal ''
513
+ error.string.must_match /invalid option: --invalid/
514
+ end
515
+
505
516
  it "errors if there are stray arguments" do
506
517
  write_file 'input', <<-EOS.demargin
507
518
  |# $frag-config: arg trailer
508
519
  EOS
509
520
  frag('input').must_equal 1
510
- (output.string + error.string).must_match /unexpected argument/
521
+ output.string.must_equal ''
522
+ error.string.must_match /unexpected argument/
511
523
  end
512
524
  end
513
525
 
@@ -584,6 +596,12 @@ describe Frag::App do
584
596
  EOS
585
597
  end
586
598
 
599
+ it "prints an error if an invalid option is given" do
600
+ frag('--invalid').must_equal 1
601
+ output.string.must_equal ''
602
+ error.string.must_match /invalid option: --invalid/
603
+ end
604
+
587
605
  it "prints an error if an input file does not exist" do
588
606
  frag('input').must_equal 1
589
607
  output.string.must_equal ''
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -64,7 +64,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  segments:
66
66
  - 0
67
- hash: -3732901048616748446
67
+ hash: 2629403589841448314
68
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  none: false
70
70
  requirements:
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  segments:
75
75
  - 0
76
- hash: -3732901048616748446
76
+ hash: 2629403589841448314
77
77
  requirements: []
78
78
  rubyforge_project:
79
79
  rubygems_version: 1.8.24