smallcage 0.2.1 → 0.2.2
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 +7 -0
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/lib/smallcage/application.rb +156 -58
- data/lib/smallcage/commands/auto.rb +14 -6
- data/lib/smallcage/erb_base.rb +7 -4
- data/lib/smallcage/renderer.rb +2 -0
- data/lib/smallcage/version.rb +1 -1
- data/smallcage.gemspec +8 -2
- data/spec/document_path_spec.rb +45 -5
- data/spec/smallcage/application_spec.rb +271 -0
- data/spec/smallcage/commands/auto_spec.rb +11 -0
- data/spec/smallcage/commands/server_spec.rb +11 -0
- metadata +8 -2
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -11,6 +11,8 @@ With SmallCage, you can
|
|
11
11
|
* manage your website with a source code management system like a Git, Subversion, and CVS.
|
12
12
|
* customize the rules of convert with Ruby.
|
13
13
|
|
14
|
+
{Please visit our wiki for more detailed discussion.}[http://wiki.github.com/bluemark/smallcage]
|
15
|
+
|
14
16
|
|
15
17
|
== Installation
|
16
18
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -31,79 +31,171 @@ class SmallCage::Application
|
|
31
31
|
self.new.execute
|
32
32
|
end
|
33
33
|
|
34
|
-
def execute
|
34
|
+
def execute(argv = ARGV)
|
35
|
+
options = parse_options(argv)
|
36
|
+
SmallCage::Runner.run(options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_options(argv)
|
40
|
+
@argv = argv
|
35
41
|
@options = {}
|
42
|
+
|
36
43
|
@parser = create_main_parser
|
37
44
|
parse_main_options
|
45
|
+
|
38
46
|
@command_parsers = create_command_parsers
|
39
47
|
parse_command
|
40
48
|
parse_command_options
|
41
|
-
|
49
|
+
|
50
|
+
@options
|
42
51
|
end
|
43
52
|
|
44
53
|
def create_main_parser
|
45
54
|
parser = OptionParser.new
|
46
55
|
parser.banner =<<BANNER
|
47
|
-
Usage: #{File.basename($0)} <subcommand> [options]
|
56
|
+
Usage: #{File.basename($0)} [options] <subcommand> [subcommand-options]
|
48
57
|
#{VERSION_NOTE}
|
49
58
|
Subcommands are:
|
50
59
|
update [path] Build smc contents.
|
51
60
|
clean [path] Remove files generated from *.smc source.
|
52
61
|
server [path] [port] Start HTTP server.
|
53
|
-
auto [path] [port]
|
62
|
+
auto [path] [port] [--bell] Start auto update server.
|
54
63
|
import [name|uri] Import project.
|
55
64
|
export [path] [outputpath] Export project.
|
56
65
|
uri [path] Print URIs.
|
57
66
|
manifest [path] Generate Manifest.html file.
|
58
67
|
|
59
|
-
Options are:
|
60
68
|
BANNER
|
69
|
+
|
70
|
+
parser.separator "Options are:"
|
71
|
+
parser.on("-h", "--help", "Show this help message.") do
|
72
|
+
puts parser
|
73
|
+
exit(true)
|
74
|
+
end
|
75
|
+
parser.on("-v", "--version", "Show version info.") do
|
76
|
+
puts VERSION_NOTE
|
77
|
+
exit(true)
|
78
|
+
end
|
79
|
+
|
80
|
+
@options[:quiet] = false
|
81
|
+
parser.on("-q", "--quiet", "Do not print message.") do |boolean|
|
82
|
+
@options[:quiet] = boolean
|
83
|
+
end
|
84
|
+
|
61
85
|
return parser
|
62
86
|
end
|
63
87
|
private :create_main_parser
|
64
88
|
|
65
89
|
def parse_main_options
|
66
|
-
@parser.
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
@parser.on("-v", "--version", "Show version info.") do
|
72
|
-
puts VERSION_NOTE
|
73
|
-
exit
|
74
|
-
end
|
75
|
-
@parser.order!(ARGV)
|
90
|
+
@parser.order!(@argv)
|
91
|
+
rescue OptionParser::InvalidOption => e
|
92
|
+
$stderr.puts e.message
|
93
|
+
exit(false)
|
76
94
|
end
|
77
95
|
private :parse_main_options
|
78
96
|
|
79
97
|
def create_command_parsers
|
80
|
-
parsers = Hash.new do |h,k|
|
81
|
-
STDERR << "no such subcommand: #{k}\n"
|
82
|
-
exit 1
|
83
|
-
end
|
84
|
-
|
85
98
|
banners = {
|
86
|
-
:update =>
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
:
|
92
|
-
|
93
|
-
|
99
|
+
:update => <<EOT,
|
100
|
+
smc update [path] [options]
|
101
|
+
path : target directory. (default:'.')
|
102
|
+
EOT
|
103
|
+
|
104
|
+
:clean => <<EOT,
|
105
|
+
smc clean [path] [options]
|
106
|
+
path : target directory (default:'.')
|
107
|
+
EOT
|
108
|
+
|
109
|
+
:server => <<EOT,
|
110
|
+
smc server [path] [port] [options]
|
111
|
+
path : target directory (default:'.')
|
112
|
+
port : HTTP server port number (default:8080)
|
113
|
+
EOT
|
114
|
+
|
115
|
+
:auto => <<EOT,
|
116
|
+
smc auto [path] [port] [options]
|
117
|
+
path : target directory (default:'.')
|
118
|
+
port : HTTP server port number (default:don't launch the server)
|
119
|
+
EOT
|
120
|
+
|
121
|
+
:import => <<EOT,
|
122
|
+
smc import [name|uri] [options]
|
123
|
+
EOT
|
124
|
+
|
125
|
+
:export => <<EOT,
|
126
|
+
smc export [path] [outputpath] [options]
|
127
|
+
EOT
|
128
|
+
|
129
|
+
:help => <<EOT,
|
130
|
+
smc help [command]
|
131
|
+
EOT
|
132
|
+
|
133
|
+
:uri => <<EOT,
|
134
|
+
smc uri [path] [options]
|
135
|
+
EOT
|
136
|
+
|
137
|
+
:manifest => <<EOT,
|
138
|
+
smc manifest [path] [options]
|
139
|
+
EOT
|
140
|
+
|
94
141
|
}
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
142
|
+
|
143
|
+
parsers = {}
|
144
|
+
banners.each do |command, banner|
|
145
|
+
parsers[command] = create_default_command_parser(banner)
|
146
|
+
end
|
147
|
+
|
148
|
+
parsers[:auto].on("--bell", "Ring bell after publishing files.") do |boolean|
|
149
|
+
@options[:bell] = boolean
|
100
150
|
end
|
101
151
|
|
102
152
|
return parsers
|
103
153
|
end
|
104
154
|
private :create_command_parsers
|
105
155
|
|
156
|
+
def create_default_command_parser(banner)
|
157
|
+
parser = OptionParser.new
|
158
|
+
parser.banner = "Usage: " + banner
|
159
|
+
parser.separator "Options are:"
|
160
|
+
|
161
|
+
# these options can place both before and after the subcommand.
|
162
|
+
parser.on("-h", "--help", "Show this help message.") do
|
163
|
+
puts parser
|
164
|
+
exit(true)
|
165
|
+
end
|
166
|
+
parser.on("-v", "--version", "Show version info.") do
|
167
|
+
puts VERSION_NOTE
|
168
|
+
exit(true)
|
169
|
+
end
|
170
|
+
parser.on("-q", "--quiet", "Do not print message.") do |boolean|
|
171
|
+
@options[:quiet] = boolean
|
172
|
+
end
|
173
|
+
|
174
|
+
return parser
|
175
|
+
end
|
176
|
+
private :create_default_command_parser
|
177
|
+
|
106
178
|
def parse_command
|
179
|
+
@options[:command] = get_command
|
180
|
+
|
181
|
+
if @options[:command].nil?
|
182
|
+
puts @parser
|
183
|
+
exit(false)
|
184
|
+
end
|
185
|
+
parser = @command_parsers[@options[:command]]
|
186
|
+
if parser.nil?
|
187
|
+
$stderr.puts "no such subcommand: #{@options[:command]}"
|
188
|
+
exit(false)
|
189
|
+
end
|
190
|
+
parser.parse!(@argv)
|
191
|
+
rescue OptionParser::InvalidOption => e
|
192
|
+
$stderr.puts e.message
|
193
|
+
exit(false)
|
194
|
+
end
|
195
|
+
private :parse_command
|
196
|
+
|
197
|
+
|
198
|
+
def get_command
|
107
199
|
commands = Hash.new {|h,k| k}
|
108
200
|
commands.merge!({
|
109
201
|
:up => :update,
|
@@ -111,59 +203,65 @@ BANNER
|
|
111
203
|
:au => :auto,
|
112
204
|
})
|
113
205
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
if @options[:command].nil?
|
120
|
-
puts @parser
|
121
|
-
exit
|
122
|
-
end
|
206
|
+
command_name = @argv.shift.to_s.strip
|
207
|
+
return nil if command_name.empty?
|
208
|
+
return commands[command_name.to_sym]
|
123
209
|
end
|
124
|
-
private :
|
210
|
+
private :get_command
|
125
211
|
|
126
212
|
def parse_command_options
|
127
213
|
if @options[:command] == :help
|
128
|
-
subcmd =
|
214
|
+
subcmd = @argv.shift
|
129
215
|
if subcmd.nil?
|
130
216
|
puts @parser
|
131
217
|
else
|
132
218
|
puts @command_parsers[subcmd.to_sym]
|
133
219
|
end
|
134
|
-
exit
|
220
|
+
exit(true)
|
135
221
|
elsif @options[:command] == :update
|
136
|
-
@options[:path] =
|
222
|
+
@options[:path] = @argv.shift
|
137
223
|
@options[:path] ||= "."
|
138
224
|
elsif @options[:command] == :server
|
139
|
-
@options[:path] =
|
140
|
-
@options[:port] = ARGV.shift
|
225
|
+
@options[:path] = @argv.shift
|
141
226
|
@options[:path] ||= "."
|
142
|
-
@options[:port]
|
227
|
+
@options[:port] = get_port_number(8080)
|
143
228
|
elsif @options[:command] == :auto
|
144
|
-
@options[:path] =
|
229
|
+
@options[:path] = @argv.shift
|
145
230
|
@options[:path] ||= "."
|
146
|
-
@options[:port] =
|
231
|
+
@options[:port] = get_port_number(nil)
|
232
|
+
@options[:bell] ||= false
|
147
233
|
elsif @options[:command] == :import
|
148
|
-
@options[:from] =
|
234
|
+
@options[:from] = @argv.shift
|
149
235
|
@options[:from] ||= "default"
|
150
|
-
@options[:to] =
|
236
|
+
@options[:to] = @argv.shift
|
151
237
|
@options[:to] ||= "."
|
152
238
|
elsif @options[:command] == :export
|
153
|
-
@options[:path] =
|
239
|
+
@options[:path] = @argv.shift
|
154
240
|
@options[:path] ||= "."
|
155
|
-
@options[:out] =
|
241
|
+
@options[:out] = @argv.shift
|
156
242
|
elsif @options[:command] == :uri
|
157
|
-
@options[:path] =
|
243
|
+
@options[:path] = @argv.shift
|
158
244
|
@options[:path] ||= "."
|
159
245
|
elsif @options[:command] == :manifest
|
160
|
-
@options[:path] =
|
246
|
+
@options[:path] = @argv.shift
|
161
247
|
@options[:path] ||= "."
|
162
248
|
elsif @options[:command] == :clean
|
163
|
-
@options[:path] =
|
249
|
+
@options[:path] = @argv.shift
|
164
250
|
@options[:path] ||= "."
|
165
251
|
end
|
166
252
|
end
|
167
253
|
private :parse_command_options
|
168
254
|
|
255
|
+
def get_port_number(default)
|
256
|
+
return default if @argv.empty?
|
257
|
+
|
258
|
+
port = @argv.shift
|
259
|
+
if port.to_i == 0
|
260
|
+
$stderr.puts "illegal port number: #{port}"
|
261
|
+
exit(false)
|
262
|
+
end
|
263
|
+
return port.to_i
|
264
|
+
end
|
265
|
+
private :get_port_number
|
266
|
+
|
169
267
|
end
|
@@ -67,7 +67,7 @@ module SmallCage::Commands
|
|
67
67
|
modified_special_files
|
68
68
|
target_files = modified_files
|
69
69
|
|
70
|
-
runner = SmallCage::Runner.new({ :path => @target })
|
70
|
+
runner = SmallCage::Runner.new({ :path => @target, :quiet => @opts[:quiet] })
|
71
71
|
begin
|
72
72
|
runner.update
|
73
73
|
rescue Exception => e
|
@@ -78,6 +78,7 @@ module SmallCage::Commands
|
|
78
78
|
|
79
79
|
update_http_server(target_files)
|
80
80
|
puts_line
|
81
|
+
notify
|
81
82
|
end
|
82
83
|
private :update_target
|
83
84
|
|
@@ -94,9 +95,9 @@ module SmallCage::Commands
|
|
94
95
|
return if target_files.empty?
|
95
96
|
target_files.each do |tf|
|
96
97
|
if tf.basename.to_s == "_dir.smc"
|
97
|
-
runner = SmallCage::Runner.new({ :path => tf.parent })
|
98
|
+
runner = SmallCage::Runner.new({ :path => tf.parent, :quiet => @opts[:quiet] })
|
98
99
|
else
|
99
|
-
runner = SmallCage::Runner.new({ :path => tf })
|
100
|
+
runner = SmallCage::Runner.new({ :path => tf, :quiet => @opts[:quiet] })
|
100
101
|
end
|
101
102
|
runner.update
|
102
103
|
end
|
@@ -107,12 +108,14 @@ module SmallCage::Commands
|
|
107
108
|
update_http_server(target_files)
|
108
109
|
end
|
109
110
|
puts_line
|
111
|
+
notify
|
110
112
|
rescue Exception => e
|
111
113
|
STDERR.puts e.to_s
|
112
114
|
STDERR.puts $@[0..4].join("\n")
|
113
115
|
STDERR.puts ":"
|
114
|
-
print "\a" unless quiet? # Bell
|
115
116
|
puts_line
|
117
|
+
notify
|
118
|
+
notify
|
116
119
|
end
|
117
120
|
private :update_modified_files
|
118
121
|
|
@@ -127,10 +130,15 @@ module SmallCage::Commands
|
|
127
130
|
def puts_line
|
128
131
|
return if quiet?
|
129
132
|
puts "-" * 60
|
130
|
-
print "\a" # Bell
|
131
133
|
end
|
132
134
|
private :puts_line
|
133
135
|
|
136
|
+
def notify
|
137
|
+
return unless @opts[:bell]
|
138
|
+
print "\a" # Bell
|
139
|
+
end
|
140
|
+
private :notify
|
141
|
+
|
134
142
|
def update_http_server(target_files)
|
135
143
|
return unless @http_server
|
136
144
|
path = target_files.find {|p| p.basename.to_s != "_dir.smc" }
|
@@ -167,4 +175,4 @@ module SmallCage::Commands
|
|
167
175
|
private :start_http_server
|
168
176
|
|
169
177
|
end
|
170
|
-
end
|
178
|
+
end
|
data/lib/smallcage/erb_base.rb
CHANGED
@@ -4,10 +4,13 @@ class SmallCage::ErbBase
|
|
4
4
|
@loader, @renderer, @obj = loader, renderer, obj
|
5
5
|
end
|
6
6
|
|
7
|
-
def method_missing(
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def method_missing(*args)
|
8
|
+
if 1 < args.length
|
9
|
+
raise NameError.new("method_missing called with more than one argument: #{@renderer.current_template} #{args.inspect}")
|
10
|
+
end
|
11
|
+
|
12
|
+
name = args[0].to_s
|
13
|
+
return @obj[name] unless @obj[name].nil?
|
11
14
|
|
12
15
|
# render if template file exists. or return nil.
|
13
16
|
return @renderer.render(name, @obj)
|
data/lib/smallcage/renderer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class SmallCage::Renderer
|
2
|
+
attr_reader :current_template
|
2
3
|
|
3
4
|
def initialize(loader)
|
4
5
|
@loader = loader
|
@@ -7,6 +8,7 @@ class SmallCage::Renderer
|
|
7
8
|
def render(name, obj)
|
8
9
|
path = @loader.template_path(name)
|
9
10
|
return nil if path.nil?
|
11
|
+
@current_template = path
|
10
12
|
return render_string(path.read, obj)
|
11
13
|
end
|
12
14
|
|
data/lib/smallcage/version.rb
CHANGED
data/smallcage.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{smallcage}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["SAITO Toshihiro", "gommmmmm", "KOSEKI Kengo"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2012-03-23}
|
13
13
|
s.default_executable = %q{smc}
|
14
14
|
s.description = %q{SmallCage is a simple, but powerful website generator. It converts content and template files, which has common elements in a website, to a plain, static website. No database, no application container, and no repeat in many pages is needed. You can keep your site well with very little work.}
|
15
15
|
s.email = %q{smallcage@googlegroups.com}
|
@@ -138,6 +138,9 @@ Gem::Specification.new do |s|
|
|
138
138
|
"spec/loader_spec.rb",
|
139
139
|
"spec/manifest_spec.rb",
|
140
140
|
"spec/misc_spec.rb",
|
141
|
+
"spec/smallcage/application_spec.rb",
|
142
|
+
"spec/smallcage/commands/auto_spec.rb",
|
143
|
+
"spec/smallcage/commands/server_spec.rb",
|
141
144
|
"spec/smallcage_spec.rb",
|
142
145
|
"spec/spec.opts",
|
143
146
|
"spec/spec_helper.rb",
|
@@ -157,6 +160,9 @@ Gem::Specification.new do |s|
|
|
157
160
|
"spec/loader_spec.rb",
|
158
161
|
"spec/manifest_spec.rb",
|
159
162
|
"spec/misc_spec.rb",
|
163
|
+
"spec/smallcage/application_spec.rb",
|
164
|
+
"spec/smallcage/commands/auto_spec.rb",
|
165
|
+
"spec/smallcage/commands/server_spec.rb",
|
160
166
|
"spec/smallcage_spec.rb",
|
161
167
|
"spec/spec_helper.rb",
|
162
168
|
"spec/update_list_spec.rb",
|
data/spec/document_path_spec.rb
CHANGED
@@ -2,10 +2,10 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
2
|
require 'smallcage'
|
3
3
|
|
4
4
|
describe SmallCage::DocumentPath do
|
5
|
-
root = Pathname.new(File.dirname(__FILE__) + "/data/htdocs1")
|
6
5
|
|
7
6
|
before do
|
8
|
-
@
|
7
|
+
@rootdir = Pathname.new(File.dirname(__FILE__) + "/data/htdocs1")
|
8
|
+
@docpath = SmallCage::DocumentPath.new(@rootdir, @rootdir + "a/b/c/index.html.smc")
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should have uri property" do
|
@@ -30,13 +30,53 @@ describe SmallCage::DocumentPath do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should return root uri" do
|
33
|
-
docpath = SmallCage::DocumentPath.new(
|
33
|
+
docpath = SmallCage::DocumentPath.new(@rootdir, @rootdir)
|
34
34
|
docpath.uri.should == "/"
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should return directory uri" do
|
38
|
-
docpath = SmallCage::DocumentPath.new(
|
38
|
+
docpath = SmallCage::DocumentPath.new(@rootdir, @rootdir + "a/b")
|
39
39
|
docpath.uri.should == "/a/b"
|
40
40
|
end
|
41
|
+
|
42
|
+
it "should raise Exception when the path doesn't exist under the root directory" do
|
43
|
+
rootdir = Pathname.new(File.dirname(__FILE__) + "/data/htdocs1")
|
44
|
+
path = Pathname.new(File.dirname(__FILE__))
|
45
|
+
|
46
|
+
ok = false
|
47
|
+
begin
|
48
|
+
docpath = SmallCage::DocumentPath.new(rootdir, path)
|
49
|
+
rescue => e
|
50
|
+
e.message.should =~ /\AIllegal path: /
|
51
|
+
ok = true
|
52
|
+
end
|
53
|
+
ok.should be_true
|
54
|
+
|
55
|
+
|
56
|
+
rootdir = Pathname.new(File.dirname(__FILE__) + "/data/htdocs1")
|
57
|
+
path = Pathname.new(File.dirname(__FILE__) + "/data/htdocs")
|
58
|
+
|
59
|
+
ok = false
|
60
|
+
begin
|
61
|
+
docpath = SmallCage::DocumentPath.new(rootdir, path)
|
62
|
+
rescue => e
|
63
|
+
e.message.should =~ /\AIllegal path: /
|
64
|
+
ok = true
|
65
|
+
end
|
66
|
+
ok.should be_true
|
67
|
+
|
68
|
+
|
69
|
+
rootdir = Pathname.new(File.dirname(__FILE__) + "/data/htdocs1")
|
70
|
+
path = Pathname.new(File.dirname(__FILE__) + "/data/htdocs2")
|
71
|
+
|
72
|
+
ok = false
|
73
|
+
begin
|
74
|
+
docpath = SmallCage::DocumentPath.new(rootdir, path)
|
75
|
+
rescue => e
|
76
|
+
e.message.should =~ /\AIllegal path: /
|
77
|
+
ok = true
|
78
|
+
end
|
79
|
+
ok.should be_true
|
80
|
+
end
|
41
81
|
|
42
|
-
end
|
82
|
+
end
|
@@ -0,0 +1,271 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
require 'smallcage'
|
3
|
+
|
4
|
+
describe SmallCage::Application do
|
5
|
+
|
6
|
+
def capture_result
|
7
|
+
status = nil
|
8
|
+
result = nil
|
9
|
+
tmpout = StringIO.new
|
10
|
+
tmperr = StringIO.new
|
11
|
+
original_out, $stdout = $stdout, tmpout
|
12
|
+
original_err, $stderr = $stderr, tmperr
|
13
|
+
begin
|
14
|
+
result = yield
|
15
|
+
rescue SystemExit => e
|
16
|
+
status = e.status
|
17
|
+
ensure
|
18
|
+
$stdout = original_out
|
19
|
+
$stderr = original_err
|
20
|
+
end
|
21
|
+
|
22
|
+
return {
|
23
|
+
:exit => status,
|
24
|
+
:result => result,
|
25
|
+
:stdout => tmpout.string,
|
26
|
+
:stderr => tmperr.string
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
before(:each) do
|
31
|
+
@target = SmallCage::Application.new
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should parse update command" do
|
35
|
+
options = @target.parse_options(["update", "."])
|
36
|
+
options.should == { :path => ".", :command => :update, :quiet => false }
|
37
|
+
|
38
|
+
options = @target.parse_options(["up", "."])
|
39
|
+
options.should == { :path => ".", :command => :update, :quiet => false }
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should parse clean command" do
|
43
|
+
options = @target.parse_options(["clean", "."])
|
44
|
+
options.should == { :path => ".", :command => :clean, :quiet => false }
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should parse server command" do
|
48
|
+
options = @target.parse_options(["server", "."])
|
49
|
+
options.should == { :path => ".", :command => :server, :quiet => false, :port => 8080 } # num
|
50
|
+
|
51
|
+
options = @target.parse_options(["sv", ".", "8080"])
|
52
|
+
options.should == { :path => ".", :command => :server, :quiet => false, :port => 8080 } # string
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should accept only number port" do
|
56
|
+
result = capture_result { @target.parse_options(["server", ".", "pot"]) }
|
57
|
+
result[:exit].should == 1
|
58
|
+
result[:stdout].should be_empty
|
59
|
+
result[:stderr].should == "illegal port number: pot\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not accept port 0" do
|
63
|
+
result = capture_result { @target.parse_options(["server", ".", "0"]) }
|
64
|
+
result[:exit].should == 1
|
65
|
+
result[:stdout].should be_empty
|
66
|
+
result[:stderr].should == "illegal port number: 0\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should parse auto command" do
|
70
|
+
options = @target.parse_options(["auto", "."])
|
71
|
+
options.should == { :path => ".", :command => :auto, :port => nil, :bell => false, :quiet => false }
|
72
|
+
|
73
|
+
options = @target.parse_options(["au", ".", "8080"])
|
74
|
+
options.should == { :path => ".", :command => :auto, :port => 8080, :bell => false, :quiet => false }
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should parse import command" do
|
78
|
+
options = @target.parse_options(["import", "base", "."])
|
79
|
+
options.should == { :command => :import, :from => "base", :to => ".", :quiet => false }
|
80
|
+
|
81
|
+
options = @target.parse_options(["import"])
|
82
|
+
options.should == { :command => :import, :from => "default", :to => ".", :quiet => false }
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should parse export command" do
|
86
|
+
options = @target.parse_options(["export", ".", "path"])
|
87
|
+
options.should == { :command => :export, :path => ".", :out => "path", :quiet => false }
|
88
|
+
|
89
|
+
options = @target.parse_options(["export"])
|
90
|
+
options.should == { :command => :export, :path => ".", :out => nil, :quiet => false }
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should parse uri command" do
|
94
|
+
options = @target.parse_options(["uri", "./path/to/target"])
|
95
|
+
options.should == { :command => :uri, :path => "./path/to/target", :quiet => false }
|
96
|
+
|
97
|
+
options = @target.parse_options(["uri"])
|
98
|
+
options.should == { :command => :uri, :path => ".", :quiet => false }
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should parse manifest command" do
|
102
|
+
options = @target.parse_options(["manifest", "./path/to/target"])
|
103
|
+
options.should == { :command => :manifest, :path => "./path/to/target", :quiet => false }
|
104
|
+
|
105
|
+
options = @target.parse_options(["manifest"])
|
106
|
+
options.should == { :command => :manifest, :path => ".", :quiet => false }
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should exit 1 if command is empty" do
|
110
|
+
result = capture_result { @target.parse_options([]) }
|
111
|
+
result[:exit].should == 1
|
112
|
+
result[:stdout].should =~ /\AUsage:/
|
113
|
+
result[:stdout].should =~ /^Subcommands are:/
|
114
|
+
result[:stderr].should be_empty
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should show help" do
|
118
|
+
result = capture_result { @target.parse_options(["help"]) }
|
119
|
+
result[:exit].should == 0
|
120
|
+
result[:stdout].should =~ /\AUsage:/
|
121
|
+
result[:stdout].should =~ /^Subcommands are:/
|
122
|
+
result[:stderr].should be_empty
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should show help if the arguments include --help" do
|
126
|
+
result = capture_result { @target.parse_options(["--help", "update"]) }
|
127
|
+
result[:exit].should == 0
|
128
|
+
result[:stdout].should =~ /\AUsage:/
|
129
|
+
result[:stdout].should =~ /^Subcommands are:/
|
130
|
+
result[:stderr].should be_empty
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should show subcommand help" do
|
134
|
+
result = capture_result { @target.parse_options(["help", "update"]) }
|
135
|
+
result[:exit].should == 0
|
136
|
+
result[:stdout].should =~ /\AUsage: smc update \[path\]/
|
137
|
+
result[:stderr].should be_empty
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should exit if the command is unknown" do
|
141
|
+
result = capture_result { @target.parse_options(["xxxx"]) }
|
142
|
+
result[:exit].should == 1
|
143
|
+
result[:stdout].should be_empty
|
144
|
+
result[:stderr].should == "no such subcommand: xxxx\n"
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should show version" do
|
148
|
+
result = capture_result { @target.parse_options(["--version", "update"]) }
|
149
|
+
result[:exit].should == 0
|
150
|
+
result[:stdout].should =~ /\ASmallCage \d+\.\d+\.\d+ - /
|
151
|
+
result[:stderr].should be_empty
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should exit when subcommand is empty" do
|
155
|
+
result = capture_result { @target.parse_options(["", "--version"]) }
|
156
|
+
result[:exit].should == 1
|
157
|
+
result[:stdout].should =~ /\AUsage:/
|
158
|
+
result[:stdout].should =~ /^Subcommands are:/
|
159
|
+
result[:stderr].should be_empty
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should ignore subcommand with --version option" do
|
163
|
+
result = capture_result { @target.parse_options(["help", "--version"]) }
|
164
|
+
result[:exit].should == 0
|
165
|
+
result[:stdout].should =~ /\ASmallCage \d+\.\d+\.\d+ - /
|
166
|
+
result[:stderr].should be_empty
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should ignore subcommand with -v option" do
|
170
|
+
result = capture_result { @target.parse_options(["help", "-v"]) }
|
171
|
+
result[:exit].should == 0
|
172
|
+
result[:stdout].should =~ /\ASmallCage \d+\.\d+\.\d+ - /
|
173
|
+
result[:stderr].should be_empty
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should ignore subcommand with --help option" do
|
177
|
+
result = capture_result { @target.parse_options(["update", "--help"]) }
|
178
|
+
result[:exit].should == 0
|
179
|
+
result[:stdout].should =~ /\AUsage: smc update \[path\] \[options\]/
|
180
|
+
result[:stderr].should be_empty
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should ignore subcommand with -h option" do
|
184
|
+
result = capture_result { @target.parse_options(["update", "-h"]) }
|
185
|
+
result[:exit].should == 0
|
186
|
+
result[:stdout].should =~ /\AUsage: smc update \[path\] \[options\]/
|
187
|
+
result[:stderr].should be_empty
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should exit with unknown main option --QQQ" do
|
191
|
+
result = capture_result { @target.parse_options(["--QQQ"]) }
|
192
|
+
result[:exit].should == 1
|
193
|
+
result[:stdout].should be_empty
|
194
|
+
result[:stderr].should == "invalid option: --QQQ\n"
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should exit with unknown sub option --QQQ" do
|
198
|
+
result = capture_result { @target.parse_options(["update", "--QQQ"]) }
|
199
|
+
result[:exit].should == 1
|
200
|
+
result[:stdout].should be_empty
|
201
|
+
result[:stderr].should == "invalid option: --QQQ\n"
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should accept auto command --bell option" do
|
205
|
+
result = capture_result { @target.parse_options(["auto", "--bell"]) }
|
206
|
+
result[:exit].should == nil
|
207
|
+
result[:stdout].should be_empty
|
208
|
+
result[:stderr].should be_empty
|
209
|
+
result[:result].should == {
|
210
|
+
:command => :auto,
|
211
|
+
:port => nil,
|
212
|
+
:path => ".",
|
213
|
+
:bell => true,
|
214
|
+
:quiet => false,
|
215
|
+
}
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should set bell option false as default" do
|
219
|
+
result = capture_result { @target.parse_options(["auto"]) }
|
220
|
+
result[:exit].should == nil
|
221
|
+
result[:stdout].should be_empty
|
222
|
+
result[:stderr].should be_empty
|
223
|
+
result[:result].should == {
|
224
|
+
:command => :auto,
|
225
|
+
:port => nil,
|
226
|
+
:path => ".",
|
227
|
+
:bell => false,
|
228
|
+
:quiet => false,
|
229
|
+
}
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should accept --quiet option" do
|
233
|
+
result = capture_result { @target.parse_options(["--quiet", "update"]) }
|
234
|
+
result[:exit].should == nil
|
235
|
+
result[:stdout].should be_empty
|
236
|
+
result[:stderr].should be_empty
|
237
|
+
result[:result].should == {
|
238
|
+
:command => :update,
|
239
|
+
:path => ".",
|
240
|
+
:quiet => true,
|
241
|
+
}
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should accept --quiet option after subcommand" do
|
245
|
+
result = capture_result { @target.parse_options(["update", "--quiet"]) }
|
246
|
+
result[:exit].should == nil
|
247
|
+
result[:stdout].should be_empty
|
248
|
+
result[:stderr].should be_empty
|
249
|
+
result[:result].should == {
|
250
|
+
:command => :update,
|
251
|
+
:path => ".",
|
252
|
+
:quiet => true,
|
253
|
+
}
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should accept --quiet option before and after subcommand" do
|
257
|
+
opts = ["--quiet", "auto", "--quiet", "path", "--bell", "80"]
|
258
|
+
result = capture_result { @target.parse_options(opts) }
|
259
|
+
result[:exit].should == nil
|
260
|
+
result[:stdout].should be_empty
|
261
|
+
result[:stderr].should be_empty
|
262
|
+
result[:result].should == {
|
263
|
+
:command => :auto,
|
264
|
+
:path => "path",
|
265
|
+
:port => 80,
|
266
|
+
:bell => true,
|
267
|
+
:quiet => true,
|
268
|
+
}
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
require 'smallcage'
|
3
|
+
require 'smallcage/commands/base'
|
4
|
+
require 'smallcage/commands/auto'
|
5
|
+
|
6
|
+
describe SmallCage::Commands::Auto do
|
7
|
+
it "should exist" do
|
8
|
+
SmallCage::Commands::Auto
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
require 'smallcage'
|
3
|
+
require 'smallcage/commands/base'
|
4
|
+
require 'smallcage/commands/server'
|
5
|
+
|
6
|
+
describe SmallCage::Commands::Server do
|
7
|
+
it "should exist" do
|
8
|
+
SmallCage::Commands::Server
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smallcage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SAITO Toshihiro
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date:
|
14
|
+
date: 2012-03-23 00:00:00 +09:00
|
15
15
|
default_executable: smc
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -153,6 +153,9 @@ files:
|
|
153
153
|
- spec/loader_spec.rb
|
154
154
|
- spec/manifest_spec.rb
|
155
155
|
- spec/misc_spec.rb
|
156
|
+
- spec/smallcage/application_spec.rb
|
157
|
+
- spec/smallcage/commands/auto_spec.rb
|
158
|
+
- spec/smallcage/commands/server_spec.rb
|
156
159
|
- spec/smallcage_spec.rb
|
157
160
|
- spec/spec.opts
|
158
161
|
- spec/spec_helper.rb
|
@@ -194,6 +197,9 @@ test_files:
|
|
194
197
|
- spec/loader_spec.rb
|
195
198
|
- spec/manifest_spec.rb
|
196
199
|
- spec/misc_spec.rb
|
200
|
+
- spec/smallcage/application_spec.rb
|
201
|
+
- spec/smallcage/commands/auto_spec.rb
|
202
|
+
- spec/smallcage/commands/server_spec.rb
|
197
203
|
- spec/smallcage_spec.rb
|
198
204
|
- spec/spec_helper.rb
|
199
205
|
- spec/update_list_spec.rb
|