getopt-declare 1.09.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +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
+ }
@@ -0,0 +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";
@@ -0,0 +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)
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.1
3
+ specification_version: 1
4
+ name: getopt-declare
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)."
9
+ require_paths:
10
+ - lib
11
+ author: Gonzalo Garramuno
12
+ email: GGarramuno@aol.com
13
+ homepage: http://getoptdeclare.rubyforge.org/
14
+ rubyforge_project:
15
+ description:
16
+ autorequire:
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: false
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ -
23
+ - ">"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.0.0
26
+ version:
27
+ platform: ruby
28
+ files:
29
+ - samples/cmdline_array.rb
30
+ - 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
+ - samples/cmdline_mid.rb
36
+ - samples/cmdline_noargv.rb
37
+ - samples/cmdline_parameters.rb
38
+ - samples/cmdline_pvtype.rb
39
+ - samples/cmdline_pvtype2.rb
40
+ - samples/cmdline_regex.rb
41
+ - samples/cmdline_singles.rb
42
+ - samples/demo_cmdline.rb
43
+ - samples/demo_csv.rb
44
+ - samples/demo_interp.rb
45
+ - samples/demo_shell.rb
46
+ - lib/Getopt
47
+ - lib/Getopt/Declare.rb
48
+ - lib/Getopt/DelimScanner.rb
49
+ test_files: []
50
+ rdoc_options: []
51
+ extra_rdoc_files: []
52
+ executables: []
53
+ extensions: []
54
+ requirements: []
55
+ dependencies: []