optparse-defaults 0.1.0
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.
- data/README.rdoc +17 -0
- data/lib/optparse/defaults.rb +43 -0
- data/man/optparse-defaults.3 +38 -0
- data/man/optparse-defaults.3.ronn +33 -0
- metadata +105 -0
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= OptionParser::Defaults
|
2
|
+
|
3
|
+
Adds support for default options to the stdlib's OptionParser.
|
4
|
+
|
5
|
+
Default options are parsed before any given command-line options, and they're
|
6
|
+
also added to the bottom of the help message.
|
7
|
+
|
8
|
+
== Usage
|
9
|
+
|
10
|
+
parser = OptionParser.with_defaults do |opts|
|
11
|
+
opts.defaults = %w(--foo --no-bar --baz=42)
|
12
|
+
# ... and so on ...
|
13
|
+
end
|
14
|
+
|
15
|
+
parser.order(ARGV)
|
16
|
+
|
17
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
class OptionParser
|
4
|
+
module Defaults
|
5
|
+
VERSION = '0.1.0'
|
6
|
+
|
7
|
+
def defaults=(defaults)
|
8
|
+
@defaults = defaults.extend(Arguments)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Note that it's important to use #order rather than #permute, to ensure
|
12
|
+
# that the given options have a chance to override the defaults. (These are
|
13
|
+
# <tt>POSIX</tt>-ly correct semantics.)
|
14
|
+
def order(*args, &block)
|
15
|
+
super(*@defaults.followed_by(*args), &block)
|
16
|
+
rescue ParseError
|
17
|
+
abort($!)
|
18
|
+
end
|
19
|
+
|
20
|
+
def help
|
21
|
+
@defaults.help(super, summary_indent)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
module Arguments #:nodoc:
|
27
|
+
def followed_by(*args)
|
28
|
+
dup.concat(args.flatten)
|
29
|
+
end
|
30
|
+
|
31
|
+
def help(before, indent)
|
32
|
+
"#{before}\nDefaults:\n#{indent}#{join ' '}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.with_defaults(*args)
|
38
|
+
new(*args) do |instance|
|
39
|
+
instance.extend(Defaults)
|
40
|
+
yield instance if block_given?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
.\" generated with Ronn/v0.5
|
2
|
+
.\" http://github.com/rtomayko/ronn/
|
3
|
+
.
|
4
|
+
.TH "OPTPARSE\-DEFAULTS" "3" "June 2010" "Matthew Todd" "RubyGems Manual"
|
5
|
+
.
|
6
|
+
.SH "NAME"
|
7
|
+
\fBoptparse\-defaults\fR \-\- default options for Ruby's OptionParser
|
8
|
+
.
|
9
|
+
.SH "SYNOPSIS"
|
10
|
+
require 'optparse/defaults'
|
11
|
+
.
|
12
|
+
.P
|
13
|
+
options = OptionParser.with_defaults do |opts|
|
14
|
+
opts.defaults = %w(\-\-foo \-\-no\-bar)
|
15
|
+
.
|
16
|
+
.br
|
17
|
+
end
|
18
|
+
.
|
19
|
+
.P
|
20
|
+
options.order(ARGV)
|
21
|
+
.
|
22
|
+
.SH "DESCRIPTION"
|
23
|
+
\fBOptionParser.with_defaults()\fR extends Ruby's OptionParser with the ability to
|
24
|
+
handle default options.
|
25
|
+
.
|
26
|
+
.P
|
27
|
+
These options are applied before any given command\-line options, and they're
|
28
|
+
also displayed at the bottom of the help text.
|
29
|
+
.
|
30
|
+
.SH "AUTHOR"
|
31
|
+
Matthew Todd, \fImatthewtodd\fR on GitHub.
|
32
|
+
.
|
33
|
+
.SH "BUGS"
|
34
|
+
For POSIX\-correctness, it's important that you call \fBOptionParser#order\fR
|
35
|
+
instead of \fBOptionParser#permute\fR.
|
36
|
+
.
|
37
|
+
.SH "SEE ALSO"
|
38
|
+
ruby(1)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
optparse-defaults(3) -- default options for Ruby's OptionParser
|
2
|
+
===============================================================
|
3
|
+
|
4
|
+
## SYNOPSIS
|
5
|
+
|
6
|
+
require 'optparse/defaults'
|
7
|
+
|
8
|
+
options = OptionParser.with_defaults do |opts|
|
9
|
+
opts.defaults = %w(--foo --no-bar)
|
10
|
+
end
|
11
|
+
|
12
|
+
options.order(ARGV)
|
13
|
+
|
14
|
+
## DESCRIPTION
|
15
|
+
|
16
|
+
`OptionParser.with_defaults()` extends Ruby's OptionParser with the ability to
|
17
|
+
handle default options.
|
18
|
+
|
19
|
+
These options are applied before any given command-line options, and they're
|
20
|
+
also displayed at the bottom of the help text.
|
21
|
+
|
22
|
+
## AUTHOR
|
23
|
+
|
24
|
+
Matthew Todd, [matthewtodd](http://github.com/matthewtodd) on GitHub.
|
25
|
+
|
26
|
+
## BUGS
|
27
|
+
|
28
|
+
For POSIX-correctness, it's important that you call `OptionParser#order`
|
29
|
+
instead of `OptionParser#permute`.
|
30
|
+
|
31
|
+
## SEE ALSO
|
32
|
+
|
33
|
+
ruby(1)
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: optparse-defaults
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matthew Todd
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-18 00:00:00 +03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
requirement: *id001
|
32
|
+
name: ronn
|
33
|
+
prerelease: false
|
34
|
+
type: :development
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
requirement: *id002
|
46
|
+
name: shoe
|
47
|
+
prerelease: false
|
48
|
+
type: :development
|
49
|
+
description: |
|
50
|
+
Default options for the stdlib's OptionParser
|
51
|
+
|
52
|
+
email: matthew.todd@gmail.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- README.rdoc
|
59
|
+
files:
|
60
|
+
- README.rdoc
|
61
|
+
- lib/optparse/defaults.rb
|
62
|
+
- man/optparse-defaults.3
|
63
|
+
- man/optparse-defaults.3.ronn
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/matthewtodd/optparse-defaults
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --main
|
71
|
+
- README.rdoc
|
72
|
+
- --title
|
73
|
+
- optparse-defaults-0.1.0
|
74
|
+
- --inline-source
|
75
|
+
- --webcvs
|
76
|
+
- http://github.com/matthewtodd/optparse-defaults/blob/v0.1.0/
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.3.7
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Default options for the stdlib's OptionParser
|
104
|
+
test_files: []
|
105
|
+
|