choosy 0.4.9 → 0.4.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +13 -1
- data/README.md +259 -0
- data/Rakefile +28 -17
- data/lib/VERSION.yml +4 -4
- data/lib/choosy.rb +38 -10
- data/lib/choosy/argument.rb +0 -2
- data/lib/choosy/base_command.rb +9 -8
- data/lib/choosy/command.rb +0 -6
- data/lib/choosy/converter.rb +0 -5
- data/lib/choosy/dsl/argument_builder.rb +0 -5
- data/lib/choosy/dsl/base_builder.rb +0 -2
- data/lib/choosy/dsl/base_command_builder.rb +54 -42
- data/lib/choosy/dsl/command_builder.rb +0 -6
- data/lib/choosy/dsl/option_builder.rb +4 -6
- data/lib/choosy/dsl/super_command_builder.rb +0 -4
- data/lib/choosy/errors.rb +10 -2
- data/lib/choosy/option.rb +0 -3
- data/lib/choosy/parse_result.rb +0 -2
- data/lib/choosy/parser.rb +0 -4
- data/lib/choosy/printing/base_printer.rb +0 -3
- data/lib/choosy/printing/color.rb +21 -33
- data/lib/choosy/printing/erb_printer.rb +0 -2
- data/lib/choosy/printing/formatting_element.rb +0 -2
- data/lib/choosy/printing/help_printer.rb +0 -3
- data/lib/choosy/printing/manpage.rb +5 -2
- data/lib/choosy/printing/manpage_printer.rb +1 -6
- data/lib/choosy/rake.rb +33 -31
- data/lib/choosy/super_command.rb +1 -7
- data/lib/choosy/super_parser.rb +0 -6
- data/lib/choosy/terminal.rb +0 -3
- data/lib/choosy/verifier.rb +0 -3
- data/lib/choosy/version.rb +0 -2
- data/spec/choosy/argument_spec.rb +0 -3
- data/spec/choosy/base_command_spec.rb +0 -3
- data/spec/choosy/command_spec.rb +0 -4
- data/spec/choosy/converter_spec.rb +0 -4
- data/spec/choosy/dsl/argument_builder_spec.rb +0 -3
- data/spec/choosy/dsl/base_builder_spec.rb +0 -3
- data/spec/choosy/dsl/base_command_builder_spec.rb +18 -5
- data/spec/choosy/dsl/commmand_builder_spec.rb +0 -6
- data/spec/choosy/dsl/option_builder_spec.rb +0 -3
- data/spec/choosy/dsl/super_command_builder_spec.rb +0 -4
- data/spec/choosy/option_spec.rb +0 -3
- data/spec/choosy/parser_spec.rb +0 -5
- data/spec/choosy/printing/base_printer_spec.rb +0 -5
- data/spec/choosy/printing/color_spec.rb +1 -4
- data/spec/choosy/printing/help_printer_spec.rb +0 -5
- data/spec/choosy/printing/manpage_printer_spec.rb +0 -4
- data/spec/choosy/printing/manpage_spec.rb +2 -3
- data/spec/choosy/super_command_spec.rb +0 -3
- data/spec/choosy/super_parser_spec.rb +0 -5
- data/spec/choosy/terminal_spec.rb +0 -3
- data/spec/choosy/verifier_spec.rb +0 -7
- data/spec/choosy/version_spec.rb +0 -2
- metadata +127 -121
- data/README.markdown +0 -463
- data/lib/choosy/printing.rb +0 -1
- data/spec/integration/command-A_spec.rb +0 -37
data/lib/choosy/command.rb
CHANGED
data/lib/choosy/converter.rb
CHANGED
@@ -1,10 +1,3 @@
|
|
1
|
-
require 'choosy/errors'
|
2
|
-
require 'choosy/dsl/option_builder'
|
3
|
-
require 'choosy/dsl/base_builder'
|
4
|
-
require 'choosy/printing/manpage_printer'
|
5
|
-
require 'choosy/printing/erb_printer'
|
6
|
-
require 'choosy/printing/formatting_element'
|
7
|
-
|
8
1
|
module Choosy::DSL
|
9
2
|
class BaseCommandBuilder
|
10
3
|
include BaseBuilder
|
@@ -76,31 +69,28 @@ module Choosy::DSL
|
|
76
69
|
evaluate_option_builder!(builder, &block)
|
77
70
|
end
|
78
71
|
|
79
|
-
|
80
|
-
|
81
|
-
next if method == :boolean || method == :bool
|
72
|
+
Choosy::Converter::CONVERSIONS.keys.each do |method|
|
73
|
+
next if method == :boolean || method == :bool
|
82
74
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
75
|
+
self.class_eval <<-EOF, __FILE__, __LINE__
|
76
|
+
def #{method}(sym, desc, config=nil, &block)
|
77
|
+
simple_option(sym, desc, true, :one, :#{method}, nil, config, &block)
|
78
|
+
end
|
87
79
|
|
88
|
-
|
89
|
-
|
90
|
-
|
80
|
+
def #{method}s(sym, desc, config=nil, &block)
|
81
|
+
simple_option(sym, desc, true, :many, :#{method}, nil, config, &block)
|
82
|
+
end
|
91
83
|
|
92
|
-
|
93
|
-
|
94
|
-
|
84
|
+
def #{method}_(sym, desc, config=nil, &block)
|
85
|
+
simple_option(sym, desc, false, :one, :#{method}, nil, config, &block)
|
86
|
+
end
|
95
87
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
88
|
+
def #{method}s_(sym, desc, config=nil, &block)
|
89
|
+
simple_option(sym, desc, false, :many, :#{method}, nil, config, &block)
|
90
|
+
end
|
91
|
+
EOF
|
101
92
|
end
|
102
93
|
|
103
|
-
create_conversions
|
104
94
|
alias :single :string
|
105
95
|
alias :single_ :string_
|
106
96
|
|
@@ -127,34 +117,56 @@ module Choosy::DSL
|
|
127
117
|
# Additional helpers
|
128
118
|
|
129
119
|
def help(msg=nil, &block)
|
130
|
-
h = OptionBuilder.new(OptionBuilder::HELP)
|
131
|
-
h.short '-h'
|
132
|
-
h.long '--help'
|
133
120
|
msg ||= "Show this help message"
|
134
|
-
h.desc msg
|
135
121
|
|
136
|
-
h.
|
137
|
-
|
138
|
-
|
122
|
+
h = OptionBuilder.new(OptionBuilder::HELP) do
|
123
|
+
short '-h'
|
124
|
+
long '--help'
|
125
|
+
desc msg
|
126
|
+
validate do
|
127
|
+
raise Choosy::HelpCalled.new(:help)
|
128
|
+
end
|
129
|
+
end
|
139
130
|
|
140
131
|
evaluate_option_builder!(h, &block)
|
141
132
|
end
|
142
133
|
|
143
134
|
def version(msg, &block)
|
144
|
-
v = OptionBuilder.new(OptionBuilder::VERSION)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
135
|
+
v = OptionBuilder.new(OptionBuilder::VERSION) do
|
136
|
+
long '--version'
|
137
|
+
desc "The version number"
|
138
|
+
cast :boolean
|
139
|
+
validate do
|
140
|
+
raise Choosy::VersionCalled.new(msg)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
option_eigenclass = class << v.entity; self; end
|
145
|
+
option_eigenclass.send :define_method, :version do
|
146
|
+
msg
|
153
147
|
end
|
154
148
|
|
155
149
|
evaluate_option_builder!(v, &block)
|
156
150
|
end
|
157
151
|
|
152
|
+
def no_color(msg, &block)
|
153
|
+
msg ||= "Disable the color"
|
154
|
+
cmd = entity
|
155
|
+
|
156
|
+
n = OptionBuilder.new(:no_color) do
|
157
|
+
long "--no-color"
|
158
|
+
desc msg
|
159
|
+
cast :boolean
|
160
|
+
validate do |args, options|
|
161
|
+
if cmd.printer.respond_to?(:color)
|
162
|
+
cmd.printer.color.disable!
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
evaluate_option_builder!(n, &block)
|
168
|
+
end
|
169
|
+
|
158
170
|
protected
|
159
171
|
def evaluate_option_builder!(builder, &block)
|
160
172
|
builder.evaluate!(&block)
|
@@ -1,9 +1,3 @@
|
|
1
|
-
require 'choosy/errors'
|
2
|
-
require 'choosy/dsl/base_command_builder'
|
3
|
-
require 'choosy/dsl/option_builder'
|
4
|
-
require 'choosy/dsl/argument_builder'
|
5
|
-
require 'choosy/printing/help_printer'
|
6
|
-
|
7
1
|
module Choosy::DSL
|
8
2
|
class CommandBuilder < BaseCommandBuilder
|
9
3
|
def executor(exec=nil, &block)
|
@@ -1,16 +1,14 @@
|
|
1
|
-
require 'choosy/option'
|
2
|
-
require 'choosy/errors'
|
3
|
-
require 'choosy/converter'
|
4
|
-
require 'choosy/dsl/argument_builder'
|
5
|
-
|
6
1
|
module Choosy::DSL
|
7
2
|
class OptionBuilder < ArgumentBuilder
|
8
3
|
HELP = :__help__
|
9
4
|
VERSION = :__version__
|
10
5
|
|
11
|
-
def initialize(name)
|
6
|
+
def initialize(name, &block)
|
12
7
|
super()
|
13
8
|
@name = name
|
9
|
+
if block_given?
|
10
|
+
self.instance_eval(&block)
|
11
|
+
end
|
14
12
|
end
|
15
13
|
|
16
14
|
def entity
|
data/lib/choosy/errors.rb
CHANGED
@@ -3,11 +3,19 @@ module Choosy
|
|
3
3
|
|
4
4
|
ConfigurationError = Class.new(Choosy::Error)
|
5
5
|
ValidationError = Class.new(Choosy::Error)
|
6
|
-
HelpCalled = Class.new(Choosy::Error)
|
7
|
-
VersionCalled = Class.new(Choosy::Error)
|
8
6
|
ConversionError = Class.new(Choosy::Error)
|
9
7
|
ParseError = Class.new(Choosy::Error)
|
10
8
|
SuperParseError = Class.new(Choosy::Error)
|
11
9
|
VersionError = Class.new(Choosy::Error)
|
12
10
|
ClientExecutionError = Class.new(Choosy::Error)
|
11
|
+
|
12
|
+
class HelpCalled < Choosy::Error
|
13
|
+
def initialize(m); @m = m; end
|
14
|
+
def message; @m; end
|
15
|
+
end
|
16
|
+
|
17
|
+
class VersionCalled < Choosy::Error
|
18
|
+
def initialize(m); @m = m; end
|
19
|
+
def message; @m; end
|
20
|
+
end
|
13
21
|
end
|
data/lib/choosy/option.rb
CHANGED
data/lib/choosy/parse_result.rb
CHANGED
data/lib/choosy/parser.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'choosy/errors'
|
2
|
-
|
3
1
|
module Choosy::Printing
|
4
2
|
class Color
|
5
3
|
# Extrapolated from:
|
@@ -27,8 +25,10 @@ module Choosy::Printing
|
|
27
25
|
:normal => 22
|
28
26
|
}
|
29
27
|
|
30
|
-
|
31
|
-
|
28
|
+
KINDS = {
|
29
|
+
:foreground => 30,
|
30
|
+
:background => 40
|
31
|
+
}
|
32
32
|
|
33
33
|
def initialize
|
34
34
|
begin
|
@@ -62,7 +62,7 @@ module Choosy::Printing
|
|
62
62
|
originally_nil = str.nil?
|
63
63
|
styles.each do |style|
|
64
64
|
if color?(style)
|
65
|
-
str = bedazzle(COLORS[style] +
|
65
|
+
str = bedazzle(COLORS[style] + KINDS[:foreground], str, originally_nil)
|
66
66
|
elsif effect?(style)
|
67
67
|
str = bedazzle(EFFECTS[style], str, originally_nil)
|
68
68
|
end
|
@@ -70,42 +70,30 @@ module Choosy::Printing
|
|
70
70
|
str
|
71
71
|
end
|
72
72
|
|
73
|
-
|
74
|
-
color
|
75
|
-
|
73
|
+
COLORS.each do |color, number|
|
74
|
+
define_method color do |*args|
|
75
|
+
raise ArgumentError, "Too many arguments, (max 2)" if args.length > 2
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
return args[0] || "" if disabled?
|
78
|
+
kind = args[1]
|
79
|
+
if kind && !KINDS.has_key?(kind)
|
80
|
+
raise ArgumentError, "Unrecognized format, only :foreground or :background supported"
|
81
|
+
end
|
82
82
|
|
83
|
-
|
84
|
-
raise ArgumentError.new("too many arguments to Color##{method} (max 2)") if args.length > 2
|
85
|
-
offset = find_state(method, args[1])
|
86
|
-
bedazzle(COLORS[method] + offset, args[0])
|
87
|
-
elsif effect?(method)
|
88
|
-
raise ArgumentError.new("too many arguments to Color##{method} (max 1)") if args.length > 1
|
89
|
-
bedazzle(EFFECTS[method], args[0])
|
90
|
-
else
|
91
|
-
raise NoMethodError.new("undefined method '#{method}' for Color")
|
83
|
+
bedazzle(number + KINDS[(kind || :foreground)], args[0])
|
92
84
|
end
|
93
85
|
end
|
94
86
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
FOREGROUND
|
102
|
-
when :background
|
103
|
-
BACKGROUND
|
104
|
-
else
|
105
|
-
raise ArgumentError.new("unrecognized state for Color##{method}, :foreground or :background only")
|
87
|
+
EFFECTS.each do |color, number|
|
88
|
+
define_method color do |*args|
|
89
|
+
raise ArgumentError, "Too many arguments, (max 1)" if args.length > 1
|
90
|
+
|
91
|
+
return args[0] || "" if disabled?
|
92
|
+
bedazzle(number, args[0])
|
106
93
|
end
|
107
94
|
end
|
108
95
|
|
96
|
+
private
|
109
97
|
def bedazzle(number, str, keep_open=nil)
|
110
98
|
prefix = "\e[#{number}m"
|
111
99
|
if str.nil?
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'choosy/errors'
|
2
|
-
|
3
1
|
module Choosy::Printing
|
4
2
|
class ManpageFormatter
|
5
3
|
def bold(line=nil)
|
@@ -34,6 +32,7 @@ module Choosy::Printing
|
|
34
32
|
class Manpage
|
35
33
|
attr_accessor :name, :section, :date, :version, :manual
|
36
34
|
attr_reader :format, :buffer
|
35
|
+
attr_accessor :column_width
|
37
36
|
|
38
37
|
def initialize
|
39
38
|
@buffer = []
|
@@ -176,6 +175,10 @@ module Choosy::Printing
|
|
176
175
|
io << "'\\\" t\n"
|
177
176
|
io << frame_outline << NEWLINE
|
178
177
|
io << PREFACE
|
178
|
+
if column_width
|
179
|
+
io << ".ll " << column_width.to_s << NEWLINE
|
180
|
+
end
|
181
|
+
|
179
182
|
@buffer.each do |line|
|
180
183
|
io << line
|
181
184
|
io << NEWLINE
|
@@ -1,9 +1,3 @@
|
|
1
|
-
require 'choosy/errors'
|
2
|
-
require 'choosy/option'
|
3
|
-
require 'choosy/dsl/option_builder'
|
4
|
-
require 'choosy/printing/base_printer'
|
5
|
-
require 'choosy/printing/manpage'
|
6
|
-
|
7
1
|
module Choosy::Printing
|
8
2
|
class ManpagePrinter < BasePrinter
|
9
3
|
attr_reader :manpage, :name, :synopsis
|
@@ -33,6 +27,7 @@ module Choosy::Printing
|
|
33
27
|
end
|
34
28
|
|
35
29
|
def format_prologue(command)
|
30
|
+
@manpage.column_width = columns
|
36
31
|
@manpage.name = command_name(command)
|
37
32
|
version_option = command.option_builders[Choosy::DSL::OptionBuilder::VERSION]
|
38
33
|
if version_option && @manpage.version.nil?
|
data/lib/choosy/rake.rb
CHANGED
@@ -40,48 +40,50 @@ module SH
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
namespace :choosy do
|
44
|
+
#########################################################################
|
45
|
+
# Version
|
46
|
+
require 'choosy/version'
|
47
|
+
|
48
|
+
desc "Shows the current version number."
|
49
|
+
task :version => ['version:load'] do
|
50
|
+
puts "Current version: #{$version.to_s}"
|
51
|
+
end
|
51
52
|
|
52
|
-
namespace :version do
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
namespace :version do
|
54
|
+
task :load do
|
55
|
+
puts Dir.pwd
|
56
|
+
if ENV['VERSION_FILE']
|
57
|
+
$version = Choosy::Version.new(ENV['VERSION_FILE'])
|
58
|
+
else
|
59
|
+
$version = Choosy::Version.load_from_lib Dir.pwd
|
60
|
+
end
|
59
61
|
end
|
60
|
-
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
[:tiny, :minor, :major].each do |type|
|
64
|
+
desc "Bumps the #{type} revision number."
|
65
|
+
task type => :load do
|
66
|
+
old = $version.to_s
|
67
|
+
$version.version!(type)
|
68
|
+
puts "Bumped version: #{old} -> #{$version}"
|
69
|
+
end
|
68
70
|
end
|
69
71
|
end
|
70
|
-
end
|
71
72
|
|
72
|
-
#########################################################################
|
73
|
-
# Release
|
74
|
-
desc "Tags the current release in git, builds the gemspec, and pushes the gem"
|
75
|
-
task :release => ['gem:clean', 'git:diff', 'gem:push', 'git:tag', 'git:push']
|
73
|
+
#########################################################################
|
74
|
+
# Release
|
75
|
+
desc "Tags the current release in git, builds the gemspec, and pushes the gem"
|
76
|
+
task :release => ['gem:clean', 'git:diff', 'gem:push', 'git:tag', 'git:push']
|
77
|
+
end
|
76
78
|
|
77
79
|
#########################################################################
|
78
80
|
# Git
|
79
81
|
namespace :git do
|
80
|
-
task :diff => ['version:load'] do
|
82
|
+
task :diff => ['choosy:version:load'] do
|
81
83
|
SH.attempt "git diff --exit-code", :error => "git diff: Your work doesn't seem to be checked in!", :quiet => true
|
82
84
|
end
|
83
85
|
|
84
|
-
task :tag => [:diff, 'version:load'] do
|
86
|
+
task :tag => [:diff, 'choosy:version:load'] do
|
85
87
|
puts "Tagging version #{$version}"
|
86
88
|
SH.attempt "git tag -a -m \"Tagging release #{$version}\" v#{$version}" do |code, contents|
|
87
89
|
puts contents
|
@@ -90,7 +92,7 @@ namespace :git do
|
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
|
-
task :push => [:diff, 'version:load'] do
|
95
|
+
task :push => [:diff, 'choosy:version:load'] do
|
94
96
|
SH.attempt "git push"
|
95
97
|
SH.attempt "git push --tags"
|
96
98
|
end
|
@@ -103,7 +105,7 @@ task :gem => ['gem:build']
|
|
103
105
|
|
104
106
|
namespace :gem do
|
105
107
|
desc "Builds the current gemspec."
|
106
|
-
task :build => ['version:load'] do
|
108
|
+
task :build => ['choosy:version:load'] do
|
107
109
|
SH.files('gemspec') do |gemspec|
|
108
110
|
puts " Building gemspec: #{gemspec}"
|
109
111
|
SH.attempt "gem build #{gemspec}"
|