getopt-declare 1.09.7 → 1.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,24 +1,27 @@
1
-
2
- require "Getopt/Declare"
3
-
4
- def encode(t)
5
- return Getopt::Declare.new(t,['-BUILD']).code
6
- end
7
-
8
- =begin
9
- Just type in something, like:
10
-
11
- =for Getopt::Declare
12
-
13
- -a Append mode
14
- =cut
15
-
16
- =end
17
-
18
- $/ = '=cut'
19
- if t = $stdin.readline
20
- t.sub!( /^=for\s+Getopt::Declare\s*\n(.*?)\n=cut/esm ) {
21
- '(self,source) = []'+encode("#$1") }
22
- end
23
-
24
- print t
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+ def encode(t)
6
+ return Getopt::Declare.new(t,['-BUILD']).code
7
+ end
8
+
9
+ =begin
10
+ Just type in something, like:
11
+
12
+ =for Getopt::Declare
13
+
14
+ -a Append mode
15
+ =cut
16
+
17
+ =end
18
+
19
+ $/ = '=cut'
20
+ if t = $stdin.readline
21
+ x = t.sub( /^=for\s+Getopt::Declare\s*\n(.*?)\n/esm ) {
22
+ '(self,source) = []'+encode("#$1")
23
+ }
24
+ puts x
25
+ end
26
+
27
+
@@ -1,39 +1,39 @@
1
- #!/usr/bin/ruby
2
-
3
- require "Getopt/Declare"
4
-
5
- def delold
6
- print "would have deleted\n"
7
- end
8
-
9
- args = Getopt::Declare.new(<<EOF)
10
-
11
- -a Process all data
12
-
13
- -b <n:n> Set mean byte length threshold to <N>
14
- { bytelen = n }
15
-
16
- +c <FILE> Create new file <FILE>
17
-
18
- --del Delete old file
19
- { delold(); }
20
-
21
- delete [ditto]
22
-
23
- e <w:i>x<h:i> Expand image to height <h> and width <w>
24
- { }
25
-
26
- -F <file>... Process named file(s)
27
- { defer { file.each {|i|
28
- process(i) } } }
29
-
30
- =getrand [<n>] Get a random number
31
- (or, optionally, <n> of them)
32
- { n = 1 unless !n.empty? }
33
-
34
- -- Traditionally indicates end of arguments
35
- { finish }
36
-
37
- EOF
38
-
39
- print args.inspect
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+ def delold
6
+ print "would have deleted\n"
7
+ end
8
+
9
+ args = Getopt::Declare.new(<<EOF)
10
+
11
+ -a Process all data
12
+
13
+ -b <n:n> Set mean byte length threshold to <N>
14
+ { bytelen = n }
15
+
16
+ +c <FILE> Create new file <FILE>
17
+
18
+ --del Delete old file
19
+ { delold(); }
20
+
21
+ delete [ditto]
22
+
23
+ e <w:i>x<h:i> Expand image to height <h> and width <w>
24
+ { }
25
+
26
+ -F <file>... Process named file(s)
27
+ { defer { file.each {|i|
28
+ process(i) } } }
29
+
30
+ =getrand [<n>] Get a random number
31
+ (or, optionally, <n> of them)
32
+ { n = 1 unless !n.empty? }
33
+
34
+ -- Traditionally indicates end of arguments
35
+ { finish }
36
+
37
+ EOF
38
+
39
+ print args.inspect
@@ -1,29 +1,29 @@
1
- #!/usr/bin/ruby
2
-
3
- require "Getopt/Declare"
4
-
5
- argv2 = '-in test'
6
-
7
- # Parse options from another string instead of ARGV
8
- args = Getopt::Declare.new(<<'EOPARAM', argv2 )
9
-
10
- ============================================================
11
- -in <infile> Input file
12
- -r[and[om]] Output in random order
13
- -p[erm[ute]] Output all permutations
14
- -out <outfile> Optional output file
15
- ============================================================
16
- EOPARAM
17
-
18
- puts args.inspect
19
-
20
- # Parse options from another string instead of ARGV
21
- argv3 = "-r -in argv3"
22
- args.parse(argv3)
23
- puts args.inspect
24
-
25
- # Parse options from another array instead of ARGV
26
- argv4 = [ '-in', 'opt with spaces' ]
27
-
28
- args.parse(['-ARGV', argv4])
29
- puts args.inspect
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+ argv2 = '-in test'
6
+
7
+ # Parse options from another string instead of ARGV
8
+ args = Getopt::Declare.new(<<'EOPARAM', argv2 )
9
+
10
+ ============================================================
11
+ -in <infile> Input file
12
+ -r[and[om]] Output in random order
13
+ -p[erm[ute]] Output all permutations
14
+ -out <outfile> Optional output file
15
+ ============================================================
16
+ EOPARAM
17
+
18
+ puts args.inspect
19
+
20
+ # Parse options from another string instead of ARGV
21
+ argv3 = "-r -in argv3"
22
+ args.parse(argv3)
23
+ puts args.inspect
24
+
25
+ # Parse options from another array instead of ARGV
26
+ argv4 = [ '-in', 'opt with spaces' ]
27
+
28
+ args.parse(['-ARGV', argv4])
29
+ puts args.inspect
@@ -1,23 +1,23 @@
1
- #!/usr/bin/ruby
2
-
3
- require "Getopt/Declare"
4
-
5
- specification = %q%
6
- -list <l>... ttt
7
- -out <out> ttt
8
- in=<infile> ttt
9
- +range <from>..<to> ttt
10
- --lines <start> - <stop> ttt
11
- ignore bad lines ttt
12
- <outfile> ttt
13
- -copy <files>... <dir> copy files to dir
14
- -range <from:i> [[..] [<to:i>] ] opt. range
15
- { to = 10 if to == "" }
16
-
17
- %
18
-
19
-
20
- args = Getopt::Declare.new(specification)
21
-
22
-
23
- puts args.inspect
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+ specification = %q%
6
+ -list <l>... ttt
7
+ -out <out> ttt
8
+ in=<infile> ttt
9
+ +range <from>..<to> ttt
10
+ --lines <start> - <stop> ttt
11
+ ignore bad lines ttt
12
+ <outfile> ttt
13
+ -copy <files>... <dir> copy files to dir
14
+ -range <from:i> [[..] [<to:i>] ] opt. range
15
+ { to = 10 if to == "" }
16
+
17
+ %
18
+
19
+
20
+ args = Getopt::Declare.new(specification)
21
+
22
+
23
+ puts args.inspect
@@ -1,20 +1,20 @@
1
- #!/usr/bin/ruby
2
-
3
- require "Getopt/Declare"
4
-
5
- args = Getopt::Declare.new( <<'EOPARAM' )
6
- [pvtype: type /AB|[OAB]/ ]
7
- [pvtype: Rh? /Rh[+-]/ ]
8
- [pvtype: days :+i {
9
- reject( (_VAL_.to_i < 14)," #{_PARAM_} (too soon!)" )
10
- }
11
- ]
12
-
13
- -donated <d:days> Days since last donation
14
- -applied <a:days> Days since applied to donate
15
-
16
- -blood <type:type> [<rh:Rh?>] Specify blood type
17
- and (optionally) rhesus factor
18
- EOPARAM
19
-
20
- print args.inspect
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+ args = Getopt::Declare.new( <<'EOPARAM' )
6
+ [pvtype: type /AB|[OAB]/ ]
7
+ [pvtype: Rh? /Rh[+-]/ ]
8
+ [pvtype: days :+i {
9
+ reject( (_VAL_ < 14)," #{_PARAM_} (too soon!)" )
10
+ }
11
+ ]
12
+
13
+ -donated <d:days> Days since last donation
14
+ -applied <a:days> Days since applied to donate
15
+
16
+ -blood <type:type> [<rh:Rh?>] Specify blood type
17
+ and (optionally) rhesus factor
18
+ EOPARAM
19
+
20
+ print args.inspect
@@ -1,20 +1,20 @@
1
- #!/usr/bin/ruby
2
-
3
- require "Getopt/Declare"
4
-
5
- specification = %q(
6
- [strict]
7
- [pvtype: num /\d+/ { reject if Time.new.localtime.day==3 } ]
8
- [pvtype: 'a num' :n { puts "a num!" } ]
9
- [pvtype: %q{nbr} :'a num' { reject $no_nbr } ]
10
-
11
- -count1 <n:num> test
12
- -count2 <n:a num> test2
13
- -count3 <n:nbr> test3
14
-
15
- )
16
-
17
- args = Getopt::Declare.new(specification)
18
-
19
- print args.inspect
20
-
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+ specification = %q(
6
+ [strict]
7
+ [pvtype: num /\d+/ { reject if Time.new.localtime.day==3 } ]
8
+ [pvtype: 'a num' :n { puts "a num!" } ]
9
+ [pvtype: %q{nbr} :'a num' { reject $no_nbr } ]
10
+
11
+ -count1 <n:num> test
12
+ -count2 <n:a num> test2
13
+ -count3 <n:nbr> test3
14
+
15
+ )
16
+
17
+ args = Getopt::Declare.new(specification)
18
+
19
+ print args.inspect
20
+
@@ -1,27 +1,27 @@
1
- #!/usr/bin/ruby
2
-
3
- require "Getopt/Declare"
4
-
5
- specification = <<-'EOFPARAMS'
6
- -ar <r:n> Set aspect ratio (will be clipped to [0..1] )
7
- {
8
- r = 0 if r < 0
9
- r = 1 if r > 1
10
- }
11
- -w <pixels:+i> Specify width in pixels
12
- -h <pixels:+i> Specify height in pixels
13
- -list <all:i>... list of numbers
14
- -range <from:i> [- [<to:i>] ] opt. range
15
- { to = 10 if to.empty? }
16
- -parity <p:/even|odd|both/> Set parity (<p> must be "even",
17
- "odd" or "both")
18
- -file <name:/\w*\.[A-Z]{3}/> File name must have a three-
19
- capital-letter extension
20
- -find <what:/(%T.)+/> ; look ahead test
21
-
22
- EOFPARAMS
23
-
24
-
25
- args = Getopt::Declare.new(specification)
26
-
27
- print args.inspect
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+ specification = <<-'EOFPARAMS'
6
+ -ar <r:n> Set aspect ratio (will be clipped to [0..1] )
7
+ {
8
+ r = 0 if r < 0
9
+ r = 1 if r > 1
10
+ }
11
+ -w <pixels:+i> Specify width in pixels
12
+ -h <pixels:+i> Specify height in pixels
13
+ -list <all:i>... list of numbers
14
+ -range <from:i> [- [<to:i>] ] opt. range
15
+ { to = 10 if to == 0 }
16
+ -parity <p:/even|odd|both/> Set parity (<p> must be "even",
17
+ "odd" or "both")
18
+ -file <name:/\w*\.[A-Z]{3}/> File name must have a three-
19
+ capital-letter extension
20
+ -find <what:/(%T.)+/> ; look ahead test
21
+
22
+ EOFPARAMS
23
+
24
+
25
+ args = Getopt::Declare.new(specification)
26
+
27
+ print args.inspect
@@ -1,28 +1,28 @@
1
- #! /usr/bin/ruby
2
-
3
- require "Getopt/Declare"
4
-
5
- # In the next example, only the <tt>-a</tt> and <tt>-b</tt> parameters may be clustered.
6
- # The <tt>-bu</tt> parameter is excluded because it consists of more than one
7
- # letter, whilst the <tt>-c</tt> and <tt>-d</tt> parameters are excluded because they
8
- # take (or may take, in <tt>-d</tt>'s case) a variable. The <tt>-e[xec]</tt> parameter
9
- # is excluded because it may take a trailing punctuator (<tt>[xec]</tt>).
10
- #
11
- # By comparison, if the directive had been <tt>[cluster: flags]</tt>, then
12
- # <tt>-bu</tt> _could_ be clustered, though <tt>-c</tt>, <tt>-d</tt> and <tt>-e[xec]</tt> would
13
- # still be excluded since they are not "pure flags").
14
- #
15
-
16
- args = Getopt::Declare.new( <<-'EOSPEC' )
17
-
18
- -a Append mode
19
- -b Back-up mode
20
- -bu [ditto]
21
- -c <file> Copy mode
22
- -d [<file>] Delete mode
23
- -e[xec] Execute mode
24
-
25
- [cluster:singles]
26
- EOSPEC
27
-
28
- print args.inspect
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+ # In the next example, only the <tt>-a</tt> and <tt>-b</tt> parameters may be clustered.
6
+ # The <tt>-bu</tt> parameter is excluded because it consists of more than one
7
+ # letter, whilst the <tt>-c</tt> and <tt>-d</tt> parameters are excluded because they
8
+ # take (or may take, in <tt>-d</tt>'s case) a variable. The <tt>-e[xec]</tt> parameter
9
+ # is excluded because it may take a trailing punctuator (<tt>[xec]</tt>).
10
+ #
11
+ # By comparison, if the directive had been <tt>[cluster: flags]</tt>, then
12
+ # <tt>-bu</tt> _could_ be clustered, though <tt>-c</tt>, <tt>-d</tt> and <tt>-e[xec]</tt> would
13
+ # still be excluded since they are not "pure flags").
14
+ #
15
+
16
+ args = Getopt::Declare.new( <<-'EOSPEC' )
17
+
18
+ -a Append mode
19
+ -b Back-up mode
20
+ -bu [ditto]
21
+ -c <file> Copy mode
22
+ -d [<file>] Delete mode
23
+ -e[xec] Execute mode
24
+
25
+ [cluster:singles]
26
+ EOSPEC
27
+
28
+ print args.inspect
@@ -1,70 +1,70 @@
1
- #! /usr/bin/ruby
2
-
3
- require "Getopt/Declare"
4
-
5
- $VERSION = "1.00b";
6
-
7
- config = Getopt::Declare.new( <<'EOCONFIG', ['-CONFIG']);
8
- [strict]
9
- min = <n> Minimum value [required]
10
- max = <n> Maximum value
11
-
12
- EOCONFIG
13
-
14
- print "min: ", config['min'], "\n" if config['min']
15
- print "max: ", config['max'], "\n" if config['max']
16
-
17
- args = Getopt::Declare.new( <<'EOARGS' )
18
- General options:
19
- [tight]
20
- -e <f:i>..<t:i> Set expansion factor to specified range
21
- [requires: <file>]
22
- { puts "k = [#{f}..#{t}]" }
23
-
24
- -e [<k:n>...] Set expansion factor to <k> (or 2 by default)
25
- [required]
26
- { k = [2] unless k
27
- print "k = [", k.join(','), "]\n"; }
28
-
29
- -b <blen:i> Use byte length of <blen>
30
- [excludes: -a +c]
31
- { print "byte len: #{blen}\n"; }
32
-
33
- <file>... Process files [required] [implies: -a]
34
- { print "files: #{file}\n"; }
35
-
36
- -a [<n:n>] Process all data [except item <n>]
37
- { print "proc all\n"; print "except #{n}\n" if n }
38
-
39
- -fab The fabulous option (is always required :-)
40
- [required]
41
- { defer { print "fabulous!\n" } }
42
-
43
- File creation options:
44
-
45
- +c <file> Create file [mutex: +c -a]
46
- { print "create: file\n"; }
47
-
48
- +d <file> Duplicate file [implies: -a and -b 8]
49
- This is a second line
50
- { print "dup (+d) $file\n"; }
51
- --dup <file> [ditto] (long form)
52
-
53
- -how <n:i> Set height to <n> [repeatable]
54
-
55
- Garbling options:
56
-
57
- -g [<seed:i>] Garble output with optional seed [requires: +c]
58
- { print "garbling with $seed\n"; }
59
- -i Case insensitive garbling [required]
60
- { print "insensitive\n"; }
61
- -s Case sensitive garbling
62
- -w WaReZ m0De 6aRBL1N6
63
-
64
- [mutex: -i -s -w]
65
- EOARGS
66
-
67
- print args.unused
68
-
69
- #args.usage();
70
- __END__
1
+ #!/bin/env ruby
2
+
3
+ require "Getopt/Declare"
4
+
5
+ $VERSION = "1.00b";
6
+
7
+ config = Getopt::Declare.new( <<'EOCONFIG', ['-CONFIG']);
8
+ [strict]
9
+ min = <n> Minimum value [required]
10
+ max = <n> Maximum value
11
+
12
+ EOCONFIG
13
+
14
+ print "min: ", config['min'], "\n" if config['min']
15
+ print "max: ", config['max'], "\n" if config['max']
16
+
17
+ args = Getopt::Declare.new( <<'EOARGS' )
18
+ General options:
19
+ [tight]
20
+ -e <f:i>..<t:i> Set expansion factor to specified range
21
+ [requires: <file>]
22
+ { puts "k = [#{f}..#{t}]" }
23
+
24
+ -e [<k:n>...] Set expansion factor to <k> (or 2 by default)
25
+ [required]
26
+ { k = [2] unless k
27
+ print "k = [", k.join(','), "]\n"; }
28
+
29
+ -b <blen:i> Use byte length of <blen>
30
+ [excludes: -a +c]
31
+ { print "byte len: #{blen}\n"; }
32
+
33
+ <file>... Process files [required] [implies: -a]
34
+ { print "files: #{file}\n"; }
35
+
36
+ -a [<n:n>] Process all data [except item <n>]
37
+ { print "proc all\n"; print "except #{n}\n" if n }
38
+
39
+ -fab The fabulous option (is always required :-)
40
+ [required]
41
+ { defer { print "fabulous!\n" } }
42
+
43
+ File creation options:
44
+
45
+ +c <file> Create file [mutex: +c -a]
46
+ { print "create: file\n"; }
47
+
48
+ +d <file> Duplicate file [implies: -a and -b 8]
49
+ This is a second line
50
+ { print "dup (+d) $file\n"; }
51
+ --dup <file> [ditto] (long form)
52
+
53
+ -how <n:i> Set height to <n> [repeatable]
54
+
55
+ Garbling options:
56
+
57
+ -g [<seed:i>] Garble output with optional seed [requires: +c]
58
+ { print "garbling with $seed\n"; }
59
+ -i Case insensitive garbling [required]
60
+ { print "insensitive\n"; }
61
+ -s Case sensitive garbling
62
+ -w WaReZ m0De 6aRBL1N6
63
+
64
+ [mutex: -i -s -w]
65
+ EOARGS
66
+
67
+ print args.unused
68
+
69
+ #args.usage();
70
+ __END__