getopt-declare 1.09.7 → 1.12

Sign up to get free protection for your applications and to get access to all the features.
data/samples/demo_csv.rb CHANGED
@@ -1,49 +1,49 @@
1
- #!/usr/bin/ruby
2
-
3
- require "Getopt/Declare"
4
-
5
- args = Getopt::Declare.new( <<EOARGS )
6
- -f <filename:if> Parse file <filename>
7
- EOARGS
8
-
9
- $students = []
10
- $absent = []
11
-
12
- data = %q{
13
- absmith,1234567,20
14
- "aesmith, the other one",7635656,DNS
15
- cat,dog,22.2
16
- 7637843,dejones,66.7
17
- rmwilliams,288721,88
18
- help me,I'm trapped,in the marks system
19
- vtthan,872829,94
20
- }
21
-
22
-
23
- csv = <<'EOCSV'
24
- <name:qs> , <id:+i> , <score:0+n> STD FORMAT [repeatable]
25
- { $students.push( {:name=>name, :id=>id, :score=>score} ) }
26
-
27
- <id:+i> , <name:qs> , <score:0+n> VARIANT FORMAT [repeatable]
28
- { $students.push( {:name=>name, :id=>id, :score=>score} ) }
29
-
30
- <name:qs> , <id:+i> , DNS DID NOT SIT [repeatable]
31
- { $absent.push( {:name=>name, :id=>id, :score=>0} ) }
32
-
33
- <other:/.+/> SOMETHING ELSE [repeatable]
34
- { print "Unknown entry format: [#{other}]\n"; }
35
- EOCSV
36
-
37
- if args["-f"]
38
- args = Getopt::Declare.new(csv,[args["-f"]])
39
- else
40
- args = Getopt::Declare.new(csv,data)
41
- end
42
-
43
- $students.each { |i|
44
- print "student:#{i[:id]} (#{i[:name]}): #{i[:score]}.\n"
45
- }
46
-
47
- $absent.each { |i|
48
- print "#{i[:id]} => #{i[:name]}: ABSENT\n"
49
- }
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+ args = Getopt::Declare.new( <<EOARGS )
6
+ -f <filename:if> Parse file <filename>
7
+ EOARGS
8
+
9
+ $students = []
10
+ $absent = []
11
+
12
+ data = %q{
13
+ absmith,1234567,20
14
+ "aesmith, the other one",7635656,DNS
15
+ cat,dog,22.2
16
+ 7637843,dejones,66.7
17
+ rmwilliams,288721,88
18
+ help me,I'm trapped,in the marks system
19
+ vtthan,872829,94
20
+ }
21
+
22
+
23
+ csv = <<'EOCSV'
24
+ <name:qs> , <id:+i> , <score:0+n> STD FORMAT [repeatable]
25
+ { $students.push( {:name=>name, :id=>id, :score=>score} ) }
26
+
27
+ <id:+i> , <name:qs> , <score:0+n> VARIANT FORMAT [repeatable]
28
+ { $students.push( {:name=>name, :id=>id, :score=>score} ) }
29
+
30
+ <name:qs> , <id:+i> , DNS DID NOT SIT [repeatable]
31
+ { $absent.push( {:name=>name, :id=>id, :score=>0} ) }
32
+
33
+ <other:/.+/> SOMETHING ELSE [repeatable]
34
+ { print "Unknown entry format: [#{other}]\n"; }
35
+ EOCSV
36
+
37
+ if args["-f"]
38
+ args = Getopt::Declare.new(csv,[args["-f"]])
39
+ else
40
+ args = Getopt::Declare.new(csv,data)
41
+ end
42
+
43
+ $students.each { |i|
44
+ print "student:#{i[:id]} (#{i[:name]}): #{i[:score]}.\n"
45
+ }
46
+
47
+ $absent.each { |i|
48
+ print "#{i[:id]} => #{i[:name]}: ABSENT\n"
49
+ }
@@ -1,44 +1,44 @@
1
- #!/usr/bin/ruby
2
-
3
- require "Getopt/Declare"
4
-
5
-
6
- @interpolator = Getopt::Declare.new(<<'EOCMDS',['-BUILD'])
7
- [cluster:none]
8
- [repeatable]
9
- [pvtype: NOTDELIM /(?:%T.)+/ ]
10
- [pvtype: WS /\s+/ ]
11
-
12
- \{{ <cmd:NOTDELIM> }}[<ws:WS>]
13
- {
14
- print "cmd=",cmd,"\n"
15
- self['result'] += (eval cmd||'').to_s
16
- self['result'] += ws if ws
17
- }
18
-
19
- <str>[<ws:WS>]
20
- { self['result'] = '' unless self['result']
21
- self['result'] += str
22
- self['result'] += ws if ws }
23
- EOCMDS
24
-
25
- def interpolate(t)
26
- @interpolator['result'] = ''
27
- @interpolator.parse(t)
28
- return @interpolator['result']
29
- end
30
-
31
-
32
- $result = 22
33
- $name = "Sam"
34
- $n = 50
35
-
36
- def average(t)
37
- sum, count = [0,0]
38
- t.each { |i| sum += i; count += 1; }
39
- return count ? sum/count : 0;
40
- end
41
-
42
- print interpolate('The person {{$name}} scored {{$result}}'), "\n";
43
- print interpolate('The pass mark was {{$result * 2}}'), "\n";
44
- print interpolate('The average of the first {{2*$n}} numbers is {{average(1..2*$n)}}'), "\n";
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+
6
+ @interpolator = Getopt::Declare.new(<<'EOCMDS',['-BUILD'])
7
+ [cluster:none]
8
+ [repeatable]
9
+ [pvtype: NOTDELIM /(?:%T.)+/ ]
10
+ [pvtype: WS /\s+/ ]
11
+
12
+ \{{ <cmd:NOTDELIM> }}[<ws:WS>]
13
+ {
14
+ print "cmd=",cmd,"\n"
15
+ self['result'] += (eval cmd||'').to_s
16
+ self['result'] += ws if ws
17
+ }
18
+
19
+ <str>[<ws:WS>]
20
+ { self['result'] = '' unless self['result']
21
+ self['result'] += str
22
+ self['result'] += ws if ws }
23
+ EOCMDS
24
+
25
+ def interpolate(t)
26
+ @interpolator['result'] = ''
27
+ @interpolator.parse(t)
28
+ return @interpolator['result']
29
+ end
30
+
31
+
32
+ $result = 22
33
+ $name = "Sam"
34
+ $n = 50
35
+
36
+ def average(t)
37
+ sum, count = [0,0]
38
+ t.each { |i| sum += i; count += 1; }
39
+ return count ? sum/count : 0;
40
+ end
41
+
42
+ print interpolate('The person {{$name}} scored {{$result}}'), "\n";
43
+ print interpolate('The pass mark was {{$result * 2}}'), "\n";
44
+ print interpolate('The average of the first {{2*$n}} numbers is {{average(1..2*$n)}}'), "\n";
@@ -1,37 +1,37 @@
1
- #!/usr/bin/ruby
2
-
3
-
4
- require "Getopt/Declare"
5
-
6
- shell_cmds = <<'EOCMDS';
7
- Commands: [repeatable]
8
-
9
- echo [-n] <words:/.*/> ECHO WITHOUT NEWLINE
10
- { print words; print "\n" unless _PUNCT_['-n'] }
11
-
12
- [pvtype: chwho /u?g?a?/]
13
- [pvtype: chwhat /r?w?x?/]
14
-
15
- chmod [-R] <who:chwho>=<what:chwhat> <files>...
16
- CHANGE FILE PERMISSIONS
17
- { files.each { |i| print "chmod who=what #{i}\n" }
18
- }
19
-
20
- help SHOW THIS SUMMARY
21
- { self.usage() }
22
-
23
- exit EXIT SHELL
24
- { finish(1) }
25
-
26
- <error:/.*/>
27
- { print "Unknown command: error\n";
28
- print "(Try the 'help' command?)\n"; }
29
- EOCMDS
30
-
31
- shell = Getopt::Declare.new(shell_cmds,['-BUILD'])
32
-
33
- # Pass a proc
34
- count = 1
35
- pt = proc { print "#{count}> "; count += 1; return $stdin.readline }
36
-
37
- shell.parse(pt)
1
+ #!/bin/env ruby
2
+
3
+
4
+ require "Getopt/Declare"
5
+
6
+ shell_cmds = <<'EOCMDS';
7
+ Commands: [repeatable]
8
+
9
+ echo [-n] <words:/.*/> ECHO WITHOUT NEWLINE
10
+ { print words; print "\n" unless _PUNCT_['-n'] }
11
+
12
+ [pvtype: chwho /u?g?a?/]
13
+ [pvtype: chwhat /r?w?x?/]
14
+
15
+ chmod [-R] <who:chwho>=<what:chwhat> <files>...
16
+ CHANGE FILE PERMISSIONS
17
+ { files.each { |i| print "chmod who=what #{i}\n" }
18
+ }
19
+
20
+ help SHOW THIS SUMMARY
21
+ { self.usage() }
22
+
23
+ exit EXIT SHELL
24
+ { finish(1) }
25
+
26
+ <error:/.*/>
27
+ { print "Unknown command: error\n";
28
+ print "(Try the 'help' command?)\n"; }
29
+ EOCMDS
30
+
31
+ shell = Getopt::Declare.new(shell_cmds,['-BUILD'])
32
+
33
+ # Pass a proc
34
+ count = 1
35
+ pt = proc { print "#{count}> "; count += 1; return $stdin.readline }
36
+
37
+ shell.parse(pt)
metadata CHANGED
@@ -3,52 +3,59 @@ rubygems_version: 0.8.1
3
3
  specification_version: 1
4
4
  name: getopt-declare
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.09.7
7
- date: 2004-10-07
8
- summary: "Comprehensive and easy to use command-line parser library using regular expressions (port of Perl's module)."
6
+ version: "1.12"
7
+ date: 2005-07-17
8
+ summary: Getopt-Declare is a command-line argument parser.
9
9
  require_paths:
10
10
  - lib
11
11
  author: Gonzalo Garramuno
12
12
  email: GGarramuno@aol.com
13
- homepage: http://getoptdeclare.rubyforge.org/
14
- rubyforge_project:
15
- description:
16
- autorequire:
13
+ homepage: http://www.rubyforge.org/projects/getoptdeclare/
14
+ rubyforge_project: getoptdeclare
15
+ description: "Comprehensive and easy to use command-line parser library using regular
16
+ expressions. Port of Conway's Perl Getopt-Declare."
17
+ autorequire: Getopt/Declare
17
18
  default_executable:
18
19
  bindir: bin
19
20
  has_rdoc: false
20
21
  required_ruby_version: !ruby/object:Gem::Version::Requirement
21
22
  requirements:
22
23
  -
23
- - ">"
24
+ - ">="
24
25
  - !ruby/object:Gem::Version
25
- version: 0.0.0
26
+ version: 1.6.8
26
27
  version:
27
28
  platform: ruby
28
29
  files:
29
- - samples/cmdline_array.rb
30
+ - lib/Getopt/Declare.rb
31
+ - lib/Getopt/DelimScanner.rb
32
+ - Declare.rdoc
33
+ - HISTORY.txt
34
+ - getoptdeclare.gemspec
35
+ test_files:
30
36
  - samples/cmdline_basic.rb
31
- - samples/cmdline_code.rb
32
- - samples/cmdline_defer.rb
33
- - samples/cmdline_file.rb
34
- - samples/cmdline_inlines.rb
35
37
  - samples/cmdline_mid.rb
36
- - samples/cmdline_noargv.rb
37
38
  - samples/cmdline_parameters.rb
39
+ - samples/cmdline_regex.rb
38
40
  - samples/cmdline_pvtype.rb
41
+ - samples/cmdline_code.rb
39
42
  - samples/cmdline_pvtype2.rb
40
- - samples/cmdline_regex.rb
41
- - samples/cmdline_singles.rb
42
- - samples/demo_cmdline.rb
43
+ - samples/cmdline_file.rb
43
44
  - samples/demo_csv.rb
44
- - samples/demo_interp.rb
45
45
  - samples/demo_shell.rb
46
- - lib/Getopt
47
- - lib/Getopt/Declare.rb
48
- - lib/Getopt/DelimScanner.rb
49
- test_files: []
46
+ - samples/demo_interp.rb
47
+ - samples/demo_cmdline.rb
48
+ - samples/cmdline_noargv.rb
49
+ - samples/cmdline_array.rb
50
+ - samples/cmdline_defer.rb
51
+ - samples/cmdline_singles.rb
52
+ - samples/cmdline_inlines.rb
53
+ - samples/cmdline_finish.rb
50
54
  rdoc_options: []
51
- extra_rdoc_files: []
55
+ extra_rdoc_files:
56
+ - Declare.rdoc
57
+ - HISTORY.txt
58
+ - getoptdeclare.gemspec
52
59
  executables: []
53
60
  extensions: []
54
61
  requirements: []