cooloptions 1.0.0 → 1.0.1
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/History.txt +6 -1
- data/Manifest.txt +2 -0
- data/README.txt +5 -0
- data/lib/cooloptions.rb +1 -1
- data/samples/literate.rb +29 -0
- data/samples/new_rails_project +27 -0
- metadata +3 -1
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -71,6 +71,11 @@ optparse & ostruct (included in Ruby standard library).
|
|
71
71
|
|
72
72
|
sudo gem install cooloptions
|
73
73
|
|
74
|
+
== CONTRIBUTE:
|
75
|
+
|
76
|
+
Drop me an email (see above) and/or check out the source at
|
77
|
+
http://terralien.com/svn/projects/cooloptions/trunk.
|
78
|
+
|
74
79
|
== LICENSE:
|
75
80
|
|
76
81
|
The RUBY License
|
data/lib/cooloptions.rb
CHANGED
data/samples/literate.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'cooloptions'
|
2
|
+
|
3
|
+
options = CoolOptions.parse!('[options] NAME') do |cooloptions|
|
4
|
+
cooloptions.on 'option STRING', 'Description', 'default' # Matches '-o string' or '--option string' or uses the 'default'.
|
5
|
+
|
6
|
+
cooloptions.on 'required VALUE', 'Required' # Because there's no default, the option is required.
|
7
|
+
|
8
|
+
cooloptions.on 'boolean', 'Boolean', false # Matches '-b' or '--boolean' or '--no-boolean'.
|
9
|
+
# Note the lack of a placeholder for the value.
|
10
|
+
|
11
|
+
cooloptions.on 'shor(t) VALUE', 'Short' # Use parens to delineate a short form other than the first char.
|
12
|
+
# Matches '-o value' or '--short value'
|
13
|
+
|
14
|
+
cooloptions.on 'k)first VALUE', 'First' # No leading paren for a short character not in the long option.
|
15
|
+
|
16
|
+
cooloptions.after do |result| # Gets called with the result of the parse _before_ returning it.
|
17
|
+
unless result.option == 'a' # Allows for easy validation of options.
|
18
|
+
cooloptions.error("Invalid format.")
|
19
|
+
end
|
20
|
+
result.name = ARGV.shift # Or grabbing additional arguments.
|
21
|
+
end
|
22
|
+
|
23
|
+
cooloptions.parser.on('-z', '--raw [STUFF]', String, # If you want to do funky optparse stuff, you can use the parser.
|
24
|
+
'Raw optparse.') do |option| # However, if you're doing more of this than of the simple stuff,
|
25
|
+
puts "RAW!" # you should consider just using optparse directly.
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
p options.option # All the options get put in to an OpenStruct keyed by their long name (with '-' becoming '_')
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'cooloptions'
|
2
|
+
|
3
|
+
options = CoolOptions.parse!("[options] PROJECTNAME") do |o|
|
4
|
+
o.on "repository URL", "Remote subversion repository."
|
5
|
+
o.on "svk", "Use svk.", true
|
6
|
+
o.on "project-path PATH", "Root of project workspaces.", File.expand_path("~/svk")
|
7
|
+
o.on "l)repository-path PATH", "Remote repository path.", "/"
|
8
|
+
o.on "mirror-path SVKPATH", "SVK mirror path.", "//"
|
9
|
+
o.on "local-pa(t)h SVKPATH", "SVK local path.", "//local"
|
10
|
+
o.on "create-structure", "Create trunk/tags/branches structure.", true
|
11
|
+
o.on "finish", "Prep and commit the new project.", true
|
12
|
+
|
13
|
+
o.after do |r|
|
14
|
+
r.project_path = File.expand_path(r.project_path)
|
15
|
+
o.error("Invalid path.") unless File.exist?(r.project_path)
|
16
|
+
r.project_name = ARGV.shift
|
17
|
+
o.error("Project name is required.") unless r.project_name
|
18
|
+
o.error("Project name is too funky.") unless /^\w+$/ =~ r.project_name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
p options.svk # => false
|
23
|
+
p options.project_path # => '/Users/ntalbott/svk'
|
24
|
+
p options.repository # => 'http://terralien.com/svn/terralien/'
|
25
|
+
p options.finish # => false
|
26
|
+
p options.create_structure # => true
|
27
|
+
p options.project_name # => 'myproject'
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: cooloptions
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
6
|
+
version: 1.0.1
|
7
7
|
date: 2006-12-09 00:00:00 -05:00
|
8
8
|
summary: CoolOptions is a simple wrapper around optparse that provides less options and more convenience.
|
9
9
|
require_paths:
|
@@ -33,6 +33,8 @@ files:
|
|
33
33
|
- README.txt
|
34
34
|
- Rakefile
|
35
35
|
- lib/cooloptions.rb
|
36
|
+
- samples/literate.rb
|
37
|
+
- samples/new_rails_project
|
36
38
|
- test/test_cooloptions.rb
|
37
39
|
test_files:
|
38
40
|
- test/test_cooloptions.rb
|