cmdparse 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,4 +1,12 @@
1
1
  ------------------------------------------------------------------------
2
+ r328 | thomas | 2005-07-05 16:10:02 +0200 (Tue, 05 Jul 2005) | 1 line
3
+ Changed paths:
4
+ M /trunk/cmdparse/Rakefile
5
+ M /trunk/cmdparse/doc/src/index.page
6
+ M /trunk/cmdparse/lib/cmdparse.rb
7
+
8
+ * added possibility to parse global options, command and local options separately
9
+ ------------------------------------------------------------------------
2
10
  r302 | thomas | 2005-06-16 12:02:37 +0200 (Thu, 16 Jun 2005) | 1 line
3
11
  Changed paths:
4
12
  M /trunk/cmdparse/doc/src/index.page
data/Rakefile CHANGED
@@ -130,13 +130,13 @@ else
130
130
 
131
131
  s.has_rdoc = true
132
132
  s.extra_rdoc_files = rd.rdoc_files.reject do |fn| fn =~ /\.rb$/ end.to_a
133
- s.rdoc_options = ['--line-numbers', '-m README']
133
+ s.rdoc_options = ['--line-numbers', '-m', 'README']
134
134
 
135
135
  #### Author and project details
136
136
 
137
137
  s.author = "Thomas Leitner"
138
138
  s.email = "t_leitner@gmx.at"
139
- s.homepage = "cmdparse.rubyforge.org"
139
+ s.homepage = "http://cmdparse.rubyforge.org"
140
140
  s.rubyforge_project = "cmdparse"
141
141
  end
142
142
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 1.0.5
data/doc/src/index.page CHANGED
@@ -12,6 +12,13 @@ Have a look around the site!
12
12
 
13
13
  h2. News
14
14
 
15
+ <b>2005-07-05 cmdparse 1.0.5 released!!!</b>
16
+
17
+ Changes:
18
+
19
+ * added possibility to parse global options, command and local options separately
20
+
21
+
15
22
  <b>2005-06-16 cmdparse 1.0.4 released!!!</b>
16
23
 
17
24
  Changes:
data/lib/cmdparse.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  #--
3
3
  #
4
- # $Id: cmdparse.rb 297 2005-06-14 09:30:22Z thomas $
4
+ # $Id: cmdparse.rb 328 2005-07-05 14:10:02Z thomas $
5
5
  #
6
6
  # cmdparse: an advanced command line parser using optparse which supports commands
7
7
  # Copyright (C) 2004 Thomas Leitner
@@ -107,7 +107,7 @@ end
107
107
  class CommandParser
108
108
 
109
109
  # The version of the command parser
110
- VERSION = [1, 0, 4]
110
+ VERSION = [1, 0, 5]
111
111
 
112
112
  # This error is thrown when an invalid command is encountered.
113
113
  class InvalidCommandError < OptionParser::ParseError
@@ -313,6 +313,33 @@ class CommandParser
313
313
  command.init( self )
314
314
  end
315
315
 
316
+ # Parses the global options.
317
+ def parse_global_options!( args )
318
+ @options.order!( args )
319
+ end
320
+
321
+ # Parses the command.
322
+ def parse_command!( args )
323
+ @parsed[:command] = args.shift
324
+ if @parsed[:command].nil?
325
+ if @default.nil?
326
+ raise NoCommandGivenError
327
+ else
328
+ @parsed[:command] = @default
329
+ end
330
+ else
331
+ raise InvalidCommandError.new( @parsed[:command] ) unless commands.include?( @parsed[:command] )
332
+ end
333
+ end
334
+
335
+ # Parses the local options. Attention: The command has to be parsed (invoke method
336
+ # +parse_command!+) before this method can be invoked.
337
+ def parse_local_options!( args )
338
+ if @parsed[:command]
339
+ commands[@parsed[:command]].options.permute!( args ) unless commands[@parsed[:command]].options.nil?
340
+ end
341
+ end
342
+
316
343
  # Calls +parse+ - implemented to mimic OptionParser
317
344
  def permute( args ); parse( args ); end
318
345
  # Calls +parse!+ - implemented to mimic OptionParser
@@ -321,41 +348,29 @@ class CommandParser
321
348
  def order( args ); parse( args ); end
322
349
  # Calls +parse!+ - implemented to mimic OptionParser
323
350
  def order!( args ); parse!( args ); end
324
-
325
351
  # see CommandParser#parse!
326
352
  def parse( args ); parse!( args.dup ); end
327
353
 
328
354
  # Parses the given argument. First it tries to parse global arguments if given. After that the
329
- # command name is analyzied and the options for the specific commands parsed. If +execCommand+
330
- # is true, the command is executed immediately. If false, the +CommandParser#execute+ has to be
331
- # called to execute the command.
332
- def parse!( args, execCommand = true )
333
- # parse global options
355
+ # command name is analyzied and the options for the specific commands parsed. If +execCommand+ is
356
+ # true, the command is executed immediately. If false, the <tt>CommandParser#execute</tt> has to
357
+ # be called to execute the command. The optional +parse+ parameter specifies what should be
358
+ # parsed. If <tt>:global</tt> is included in the +parse+ array, global options are parsed; if
359
+ # <tt>:command</tt> is included, the command is parsed and if <tt>:local</tt> is included, the
360
+ # local options are parsed.
361
+ def parse!( args, execCommand = true, parse = [:global, :command, :local] )
334
362
  begin
335
- @options.order!( args )
336
- @parsed[:command] = args.shift
337
- if @parsed[:command].nil?
338
- if @default.nil?
339
- raise NoCommandGivenError
340
- else
341
- @parsed[:command] = @default
342
- end
343
- else
344
- raise InvalidCommandError.new( @parsed[:command] ) unless commands.include?( @parsed[:command] )
345
- end
346
- rescue OptionParser::ParseError => e
347
- handle_exception( e, :global )
348
- end
363
+ context = :global
364
+ parse_global_options!( args ) if parse.include?( :global )
365
+ parse_command!( args ) if parse.include?( :command )
349
366
 
350
- # parse local options
351
- begin
352
- commands[@parsed[:command]].options.permute!( args ) unless commands[@parsed[:command]].options.nil?
367
+ context = :local
368
+ parse_local_options!( args ) if parse.include?( :local )
353
369
  rescue OptionParser::ParseError => e
354
- handle_exception( e, :local )
370
+ handle_exception( e, context )
355
371
  end
356
372
 
357
373
  @parsed[:args] = args
358
-
359
374
  execute if execCommand
360
375
  end
361
376
 
metadata CHANGED
@@ -3,13 +3,13 @@ rubygems_version: 0.8.6
3
3
  specification_version: 1
4
4
  name: cmdparse
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.4
7
- date: 2005-06-16
6
+ version: 1.0.5
7
+ date: 2005-07-05
8
8
  summary: An advanced command line parser using optparse which supports commands
9
9
  require_paths:
10
10
  - lib
11
11
  email: t_leitner@gmx.at
12
- homepage: cmdparse.rubyforge.org
12
+ homepage: http://cmdparse.rubyforge.org
13
13
  rubyforge_project: cmdparse
14
14
  description: "cmdparse extends the default option parser 'optparse' by adding support for
15
15
  commands. Programs that use such command line interfaces are, for example,
@@ -53,7 +53,8 @@ files:
53
53
  test_files: []
54
54
  rdoc_options:
55
55
  - "--line-numbers"
56
- - "-m README"
56
+ - "-m"
57
+ - README
57
58
  extra_rdoc_files:
58
59
  - README
59
60
  executables: []