nanoc 2.2.2 → 3.0.0a1
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/bin/nanoc +29 -11
- data/bin/nanoc-select +85 -0
- metadata +27 -161
- data/ChangeLog +0 -3
- data/LICENSE +0 -19
- data/README +0 -75
- data/Rakefile +0 -76
- data/lib/nanoc.rb +0 -73
- data/lib/nanoc/base.rb +0 -26
- data/lib/nanoc/base/asset.rb +0 -117
- data/lib/nanoc/base/asset_defaults.rb +0 -21
- data/lib/nanoc/base/asset_rep.rb +0 -282
- data/lib/nanoc/base/binary_filter.rb +0 -44
- data/lib/nanoc/base/code.rb +0 -41
- data/lib/nanoc/base/compiler.rb +0 -67
- data/lib/nanoc/base/core_ext.rb +0 -2
- data/lib/nanoc/base/core_ext/hash.rb +0 -78
- data/lib/nanoc/base/core_ext/string.rb +0 -8
- data/lib/nanoc/base/data_source.rb +0 -286
- data/lib/nanoc/base/defaults.rb +0 -30
- data/lib/nanoc/base/filter.rb +0 -93
- data/lib/nanoc/base/layout.rb +0 -91
- data/lib/nanoc/base/notification_center.rb +0 -66
- data/lib/nanoc/base/page.rb +0 -132
- data/lib/nanoc/base/page_defaults.rb +0 -20
- data/lib/nanoc/base/page_rep.rb +0 -324
- data/lib/nanoc/base/plugin.rb +0 -71
- data/lib/nanoc/base/proxies.rb +0 -5
- data/lib/nanoc/base/proxies/asset_proxy.rb +0 -29
- data/lib/nanoc/base/proxies/asset_rep_proxy.rb +0 -26
- data/lib/nanoc/base/proxies/layout_proxy.rb +0 -25
- data/lib/nanoc/base/proxies/page_proxy.rb +0 -35
- data/lib/nanoc/base/proxies/page_rep_proxy.rb +0 -28
- data/lib/nanoc/base/proxy.rb +0 -37
- data/lib/nanoc/base/router.rb +0 -72
- data/lib/nanoc/base/site.rb +0 -274
- data/lib/nanoc/base/template.rb +0 -64
- data/lib/nanoc/binary_filters.rb +0 -1
- data/lib/nanoc/binary_filters/image_science_thumbnail.rb +0 -28
- data/lib/nanoc/cli.rb +0 -9
- data/lib/nanoc/cli/base.rb +0 -132
- data/lib/nanoc/cli/commands.rb +0 -10
- data/lib/nanoc/cli/commands/autocompile.rb +0 -80
- data/lib/nanoc/cli/commands/compile.rb +0 -311
- data/lib/nanoc/cli/commands/create_layout.rb +0 -85
- data/lib/nanoc/cli/commands/create_page.rb +0 -85
- data/lib/nanoc/cli/commands/create_site.rb +0 -323
- data/lib/nanoc/cli/commands/create_template.rb +0 -76
- data/lib/nanoc/cli/commands/help.rb +0 -69
- data/lib/nanoc/cli/commands/info.rb +0 -125
- data/lib/nanoc/cli/commands/switch.rb +0 -141
- data/lib/nanoc/cli/commands/update.rb +0 -91
- data/lib/nanoc/cli/logger.rb +0 -72
- data/lib/nanoc/data_sources.rb +0 -2
- data/lib/nanoc/data_sources/filesystem.rb +0 -707
- data/lib/nanoc/data_sources/filesystem_combined.rb +0 -495
- data/lib/nanoc/extra.rb +0 -6
- data/lib/nanoc/extra/auto_compiler.rb +0 -285
- data/lib/nanoc/extra/context.rb +0 -22
- data/lib/nanoc/extra/core_ext.rb +0 -2
- data/lib/nanoc/extra/core_ext/hash.rb +0 -54
- data/lib/nanoc/extra/core_ext/time.rb +0 -13
- data/lib/nanoc/extra/file_proxy.rb +0 -29
- data/lib/nanoc/extra/vcs.rb +0 -48
- data/lib/nanoc/extra/vcses.rb +0 -5
- data/lib/nanoc/extra/vcses/bazaar.rb +0 -21
- data/lib/nanoc/extra/vcses/dummy.rb +0 -20
- data/lib/nanoc/extra/vcses/git.rb +0 -21
- data/lib/nanoc/extra/vcses/mercurial.rb +0 -21
- data/lib/nanoc/extra/vcses/subversion.rb +0 -21
- data/lib/nanoc/filters.rb +0 -16
- data/lib/nanoc/filters/bluecloth.rb +0 -13
- data/lib/nanoc/filters/erb.rb +0 -19
- data/lib/nanoc/filters/erubis.rb +0 -14
- data/lib/nanoc/filters/haml.rb +0 -21
- data/lib/nanoc/filters/markaby.rb +0 -14
- data/lib/nanoc/filters/maruku.rb +0 -14
- data/lib/nanoc/filters/old.rb +0 -19
- data/lib/nanoc/filters/rainpress.rb +0 -13
- data/lib/nanoc/filters/rdiscount.rb +0 -13
- data/lib/nanoc/filters/rdoc.rb +0 -23
- data/lib/nanoc/filters/redcloth.rb +0 -14
- data/lib/nanoc/filters/relativize_paths.rb +0 -16
- data/lib/nanoc/filters/relativize_paths_in_css.rb +0 -16
- data/lib/nanoc/filters/relativize_paths_in_html.rb +0 -16
- data/lib/nanoc/filters/rubypants.rb +0 -14
- data/lib/nanoc/filters/sass.rb +0 -18
- data/lib/nanoc/helpers.rb +0 -9
- data/lib/nanoc/helpers/blogging.rb +0 -217
- data/lib/nanoc/helpers/capturing.rb +0 -63
- data/lib/nanoc/helpers/filtering.rb +0 -54
- data/lib/nanoc/helpers/html_escape.rb +0 -25
- data/lib/nanoc/helpers/link_to.rb +0 -113
- data/lib/nanoc/helpers/render.rb +0 -49
- data/lib/nanoc/helpers/tagging.rb +0 -56
- data/lib/nanoc/helpers/text.rb +0 -38
- data/lib/nanoc/helpers/xml_sitemap.rb +0 -63
- data/lib/nanoc/routers.rb +0 -3
- data/lib/nanoc/routers/default.rb +0 -54
- data/lib/nanoc/routers/no_dirs.rb +0 -66
- data/lib/nanoc/routers/versioned.rb +0 -79
- data/vendor/cri/ChangeLog +0 -0
- data/vendor/cri/LICENSE +0 -19
- data/vendor/cri/NEWS +0 -0
- data/vendor/cri/README +0 -4
- data/vendor/cri/Rakefile +0 -25
- data/vendor/cri/lib/cri.rb +0 -12
- data/vendor/cri/lib/cri/base.rb +0 -153
- data/vendor/cri/lib/cri/command.rb +0 -104
- data/vendor/cri/lib/cri/core_ext.rb +0 -8
- data/vendor/cri/lib/cri/core_ext/string.rb +0 -41
- data/vendor/cri/lib/cri/option_parser.rb +0 -186
- data/vendor/cri/test/test_base.rb +0 -6
- data/vendor/cri/test/test_command.rb +0 -6
- data/vendor/cri/test/test_core_ext.rb +0 -21
- data/vendor/cri/test/test_option_parser.rb +0 -279
data/lib/nanoc/routers.rb
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
module Nanoc::Routers
|
|
2
|
-
|
|
3
|
-
# The default router organises pages in the most obvious, but sometimes
|
|
4
|
-
# slightly restrictive, way: the hierarchy of compiled pages and assets is
|
|
5
|
-
# the same as the hierarchy of uncompiled pages and assets.
|
|
6
|
-
class Default < Nanoc::Router
|
|
7
|
-
|
|
8
|
-
identifier :default
|
|
9
|
-
|
|
10
|
-
def path_for_page_rep(page_rep)
|
|
11
|
-
# Get data we need
|
|
12
|
-
filename = page_rep.attribute_named(:filename)
|
|
13
|
-
extension = page_rep.attribute_named(:extension)
|
|
14
|
-
|
|
15
|
-
# Initialize path
|
|
16
|
-
path = page_rep.page.path + filename
|
|
17
|
-
|
|
18
|
-
# Add rep name if necessary
|
|
19
|
-
unless page_rep.name == :default
|
|
20
|
-
path += '-' + page_rep.name.to_s
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Add extension
|
|
24
|
-
path += '.' + extension
|
|
25
|
-
|
|
26
|
-
# Done
|
|
27
|
-
path
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def path_for_asset_rep(asset_rep)
|
|
31
|
-
# Get data we need
|
|
32
|
-
extension = asset_rep.attribute_named(:extension)
|
|
33
|
-
modified_path = asset_rep.asset.path[0..-2]
|
|
34
|
-
version = asset_rep.attribute_named(:version)
|
|
35
|
-
|
|
36
|
-
# Initialize path
|
|
37
|
-
assets_prefix = @site.config[:assets_prefix] || '/assets'
|
|
38
|
-
path = assets_prefix + modified_path
|
|
39
|
-
|
|
40
|
-
# Add rep name if necessary
|
|
41
|
-
unless asset_rep.name == :default
|
|
42
|
-
path += '-' + asset_rep.name.to_s
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# Add extension
|
|
46
|
-
path += '.' + extension
|
|
47
|
-
|
|
48
|
-
# Done
|
|
49
|
-
path
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
module Nanoc::Routers
|
|
2
|
-
|
|
3
|
-
# The no-directories router organises pages very similarly to the default
|
|
4
|
-
# router, but does not create directories unless necessary. This router will
|
|
5
|
-
# therefore generate pages with less pretty URLs.
|
|
6
|
-
#
|
|
7
|
-
# For example, a page with path /about/ will be written to /about.html
|
|
8
|
-
# instead of /about/index.html.
|
|
9
|
-
class NoDirs < Nanoc::Router
|
|
10
|
-
|
|
11
|
-
identifier :no_dirs
|
|
12
|
-
|
|
13
|
-
def path_for_page_rep(page_rep)
|
|
14
|
-
# Get data we need
|
|
15
|
-
filename = page_rep.attribute_named(:filename)
|
|
16
|
-
extension = page_rep.attribute_named(:extension)
|
|
17
|
-
|
|
18
|
-
# Initialize path
|
|
19
|
-
if page_rep.page.path == '/'
|
|
20
|
-
path = '/' + filename
|
|
21
|
-
else
|
|
22
|
-
path = page_rep.page.path[0..-2]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Add rep name if necessary
|
|
26
|
-
unless page_rep.name == :default
|
|
27
|
-
path += '-' + page_rep.name.to_s
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Add extension
|
|
31
|
-
path += '.' + extension
|
|
32
|
-
|
|
33
|
-
# Done
|
|
34
|
-
path
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def path_for_asset_rep(asset_rep)
|
|
38
|
-
# Get data we need
|
|
39
|
-
extension = asset_rep.attribute_named(:extension)
|
|
40
|
-
modified_path = asset_rep.asset.path[0..-2]
|
|
41
|
-
version = asset_rep.attribute_named(:version)
|
|
42
|
-
|
|
43
|
-
# Initialize path
|
|
44
|
-
assets_prefix = @site.config[:assets_prefix] || '/assets'
|
|
45
|
-
path = assets_prefix + modified_path
|
|
46
|
-
|
|
47
|
-
# Add version if necessary
|
|
48
|
-
unless version.nil?
|
|
49
|
-
path += '-v' + version.to_s
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# Add rep name
|
|
53
|
-
unless asset_rep.name == :default
|
|
54
|
-
path += '-' + asset_rep.name.to_s
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# Add extension
|
|
58
|
-
path += '.' + extension
|
|
59
|
-
|
|
60
|
-
# Done
|
|
61
|
-
path
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
end
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
module Nanoc::Routers
|
|
2
|
-
|
|
3
|
-
# The versioned router behaves pretty much like the default router, with the
|
|
4
|
-
# exception that asset representations (but not page representations) can
|
|
5
|
-
# have versions which will be added to generated URLs.
|
|
6
|
-
#
|
|
7
|
-
# This is very useful if you want to cache assets aggressively by sending an
|
|
8
|
-
# +Expires+ header to clients. An +Expires+ header usually has the issue
|
|
9
|
-
# that clients will not request the asset even if it has changed; giving the
|
|
10
|
-
# asset a different version will cause the URL to be changed, which in turn
|
|
11
|
-
# will cause the client to request the new asset.
|
|
12
|
-
#
|
|
13
|
-
# = Example
|
|
14
|
-
#
|
|
15
|
-
# For example, the URL of a textual asset containing the CSS stylesheet with
|
|
16
|
-
# its 'version' attribute set to 28 will become /assets/style-v28.css.
|
|
17
|
-
#
|
|
18
|
-
# To link to the stylesheet in a DRY way,
|
|
19
|
-
# give the asset a unique name (such as 'style') and then do something along
|
|
20
|
-
# this way:
|
|
21
|
-
#
|
|
22
|
-
# <link rel="stylesheet"
|
|
23
|
-
# type="text/css"
|
|
24
|
-
# media="screen"
|
|
25
|
-
# href="<%= @assets.find { |a| a.asset_id == 'style' }.path %>">
|
|
26
|
-
class Versioned < Nanoc::Router
|
|
27
|
-
|
|
28
|
-
identifier :versioned
|
|
29
|
-
|
|
30
|
-
def path_for_page_rep(page_rep)
|
|
31
|
-
# Get data we need
|
|
32
|
-
filename = page_rep.attribute_named(:filename)
|
|
33
|
-
extension = page_rep.attribute_named(:extension)
|
|
34
|
-
|
|
35
|
-
# Initialize path
|
|
36
|
-
path = page_rep.page.path + filename
|
|
37
|
-
|
|
38
|
-
# Add rep name if necessary
|
|
39
|
-
unless page_rep.name == :default
|
|
40
|
-
path += '-' + page_rep.name.to_s
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Add extension
|
|
44
|
-
path += '.' + extension
|
|
45
|
-
|
|
46
|
-
# Done
|
|
47
|
-
path
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def path_for_asset_rep(asset_rep)
|
|
51
|
-
# Get data we need
|
|
52
|
-
extension = asset_rep.attribute_named(:extension)
|
|
53
|
-
modified_path = asset_rep.asset.path[0..-2]
|
|
54
|
-
version = asset_rep.attribute_named(:version)
|
|
55
|
-
|
|
56
|
-
# Initialize path
|
|
57
|
-
assets_prefix = @site.config[:assets_prefix] || '/assets'
|
|
58
|
-
path = assets_prefix + modified_path
|
|
59
|
-
|
|
60
|
-
# Add version if necessary
|
|
61
|
-
unless version.nil?
|
|
62
|
-
path += '-v' + version.to_s
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# Add rep name
|
|
66
|
-
unless asset_rep.name == :default
|
|
67
|
-
path += '-' + asset_rep.name.to_s
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# Add extension
|
|
71
|
-
path += '.' + extension
|
|
72
|
-
|
|
73
|
-
# Done
|
|
74
|
-
path
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
end
|
data/vendor/cri/ChangeLog
DELETED
|
File without changes
|
data/vendor/cri/LICENSE
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2009 Denis Defreyne and contributors
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
in the Software without restriction, including without limitation the rights
|
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
furnished to do so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in all
|
|
11
|
-
copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
-
SOFTWARE.
|
data/vendor/cri/NEWS
DELETED
|
File without changes
|
data/vendor/cri/README
DELETED
data/vendor/cri/Rakefile
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
##### Requirements
|
|
2
|
-
|
|
3
|
-
# Rake etc
|
|
4
|
-
require 'rake'
|
|
5
|
-
require 'minitest/unit'
|
|
6
|
-
|
|
7
|
-
# Cri itself
|
|
8
|
-
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/lib'))
|
|
9
|
-
require 'cri'
|
|
10
|
-
|
|
11
|
-
##### Testing
|
|
12
|
-
|
|
13
|
-
desc 'Runs all tests'
|
|
14
|
-
task :test do
|
|
15
|
-
ENV['QUIET'] ||= 'true'
|
|
16
|
-
|
|
17
|
-
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/..'))
|
|
18
|
-
|
|
19
|
-
MiniTest::Unit.autorun
|
|
20
|
-
|
|
21
|
-
test_files = Dir['test/test_*.rb']
|
|
22
|
-
test_files.each { |f| require f }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
task :default => :test
|
data/vendor/cri/lib/cri.rb
DELETED
data/vendor/cri/lib/cri/base.rb
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
module Cri
|
|
2
|
-
|
|
3
|
-
# Cri::Base is the central class representing a commandline tool. It has a
|
|
4
|
-
# list of commands.
|
|
5
|
-
class Base
|
|
6
|
-
|
|
7
|
-
# The CLI's list of commands (should also contain the help command)
|
|
8
|
-
attr_reader :commands
|
|
9
|
-
|
|
10
|
-
# The CLI's help command (required)
|
|
11
|
-
attr_accessor :help_command
|
|
12
|
-
|
|
13
|
-
# Creates a new instance of the commandline tool.
|
|
14
|
-
def initialize(tool_name)
|
|
15
|
-
@tool_name = tool_name
|
|
16
|
-
|
|
17
|
-
@commands = []
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Parses the given commandline arguments and executes the requested
|
|
21
|
-
# command.
|
|
22
|
-
def run(args)
|
|
23
|
-
# Check arguments
|
|
24
|
-
if args.length == 0
|
|
25
|
-
@help_command.run([], [])
|
|
26
|
-
exit 1
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Partition options
|
|
30
|
-
opts_before_command = []
|
|
31
|
-
command_name = nil
|
|
32
|
-
opts_and_args_after_command = []
|
|
33
|
-
stage = 0
|
|
34
|
-
args.each do |arg|
|
|
35
|
-
# Update stage if necessary
|
|
36
|
-
stage = 1 if stage == 0 && !is_option?(arg)
|
|
37
|
-
|
|
38
|
-
# Add
|
|
39
|
-
opts_before_command << arg if stage == 0
|
|
40
|
-
command_name = arg if stage == 1
|
|
41
|
-
opts_and_args_after_command << arg if stage == 2
|
|
42
|
-
|
|
43
|
-
# Update stage if necessary
|
|
44
|
-
stage = 2 if stage == 1
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Handle options before command
|
|
48
|
-
begin
|
|
49
|
-
parsed_arguments = Cri::OptionParser.parse(opts_before_command, global_option_definitions)
|
|
50
|
-
rescue Cri::OptionParser::IllegalOptionError => e
|
|
51
|
-
$stderr.puts "illegal option -- #{e}"
|
|
52
|
-
exit 1
|
|
53
|
-
end
|
|
54
|
-
parsed_arguments[:options].keys.each do |option|
|
|
55
|
-
handle_option(option)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Get command
|
|
59
|
-
if command_name.nil?
|
|
60
|
-
$stderr.puts "no command given"
|
|
61
|
-
exit 1
|
|
62
|
-
end
|
|
63
|
-
command = command_named(command_name)
|
|
64
|
-
if command.nil?
|
|
65
|
-
$stderr.puts "no such command: #{command_name}"
|
|
66
|
-
exit 1
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# Parse arguments
|
|
70
|
-
option_definitions = command.option_definitions + global_option_definitions
|
|
71
|
-
begin
|
|
72
|
-
parsed_arguments = Cri::OptionParser.parse(opts_and_args_after_command, option_definitions)
|
|
73
|
-
rescue Cri::OptionParser::IllegalOptionError => e
|
|
74
|
-
$stderr.puts "illegal option -- #{e}"
|
|
75
|
-
exit 1
|
|
76
|
-
rescue Cri::OptionParser::OptionRequiresAnArgumentError => e
|
|
77
|
-
$stderr.puts "option requires an argument -- #{e}"
|
|
78
|
-
exit 1
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# Handle global options
|
|
82
|
-
global_options = global_option_definitions.map { |o| o[:long] }
|
|
83
|
-
global_options.delete_if { |o| !parsed_arguments[:options].keys.include?(o.to_sym) }
|
|
84
|
-
global_options.each { |o| handle_option(o.to_sym) }
|
|
85
|
-
|
|
86
|
-
if parsed_arguments[:options].has_key?(:help)
|
|
87
|
-
# Show help for this command
|
|
88
|
-
show_help(command)
|
|
89
|
-
else
|
|
90
|
-
# Run command
|
|
91
|
-
command.run(parsed_arguments[:options], parsed_arguments[:arguments])
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
# Returns the command with the given name.
|
|
96
|
-
def command_named(name)
|
|
97
|
-
# Find by exact name or alias
|
|
98
|
-
command = @commands.find { |c| c.name == name or c.aliases.include?(name) }
|
|
99
|
-
return command unless command.nil?
|
|
100
|
-
|
|
101
|
-
# Find by approximation
|
|
102
|
-
commands = @commands.select { |c| c.name[0, name.length] == name }
|
|
103
|
-
if commands.length > 1
|
|
104
|
-
$stderr.puts "#{@tool_name}: '#{name}' is ambiguous:"
|
|
105
|
-
$stderr.puts " #{commands.map { |c| c.name }.join(' ') }"
|
|
106
|
-
exit 1
|
|
107
|
-
elsif commands.length == 0
|
|
108
|
-
$stderr.puts "#{@tool_name}: unknown command '#{name}'\n"
|
|
109
|
-
show_help
|
|
110
|
-
exit 1
|
|
111
|
-
else
|
|
112
|
-
return commands[0]
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
# Shows the help text for the given command, or shows the general help
|
|
117
|
-
# text if no command is given.
|
|
118
|
-
def show_help(command=nil)
|
|
119
|
-
if command.nil?
|
|
120
|
-
@help_command.run([], [])
|
|
121
|
-
else
|
|
122
|
-
@help_command.run([], [ command.name ])
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
# Returns the list of global option definitionss.
|
|
127
|
-
def global_option_definitions
|
|
128
|
-
[]
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
# Adds the given command to the list of commands. Adding a command will
|
|
132
|
-
# also cause the command's +base+ to be set to this instance.
|
|
133
|
-
def add_command(command)
|
|
134
|
-
@commands << command
|
|
135
|
-
command.base = self
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
# Handles the given optio
|
|
139
|
-
def handle_option(option)
|
|
140
|
-
false
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
private
|
|
144
|
-
|
|
145
|
-
# Returns true if the given string is an option (i.e. -foo or --foo),
|
|
146
|
-
# false otherwise.
|
|
147
|
-
def is_option?(string)
|
|
148
|
-
string =~ /^-/
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
end
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
module Cri
|
|
2
|
-
|
|
3
|
-
# Cri::Command represents a command that can be executed on the commandline.
|
|
4
|
-
# It is an abstract superclass for all commands.
|
|
5
|
-
class Command
|
|
6
|
-
|
|
7
|
-
attr_accessor :base
|
|
8
|
-
|
|
9
|
-
# Returns a string containing the name of thi command. Subclasses must
|
|
10
|
-
# implement this method.
|
|
11
|
-
def name
|
|
12
|
-
raise NotImplementedError.new("Command subclasses should override #name")
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# Returns an array of strings containing the aliases for this command.
|
|
16
|
-
# Subclasses must implement this method.
|
|
17
|
-
def aliases
|
|
18
|
-
raise NotImplementedError.new("Command subclasses should override #aliases")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# Returns a string containing this command's short description, which
|
|
22
|
-
# should not be longer than 50 characters. Subclasses must implement this
|
|
23
|
-
# method.
|
|
24
|
-
def short_desc
|
|
25
|
-
raise NotImplementedError.new("Command subclasses should override #short_desc")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Returns a string containing this command's complete description, which
|
|
29
|
-
# should explain what this command does and how it works in detail.
|
|
30
|
-
# Subclasses must implement this method.
|
|
31
|
-
def long_desc
|
|
32
|
-
raise NotImplementedError.new("Command subclasses should override #long_desc")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Returns a string containing this command's usage. Subclasses must
|
|
36
|
-
# implement this method.
|
|
37
|
-
def usage
|
|
38
|
-
raise NotImplementedError.new("Command subclasses should override #usage")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Returns an array containing this command's option definitions. See the
|
|
42
|
-
# documentation for Cri::OptionParser for details on what option
|
|
43
|
-
# definitions look like. Subclasses may implement this method if the
|
|
44
|
-
# command has options.
|
|
45
|
-
def option_definitions
|
|
46
|
-
[]
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# Executes the command. Subclasses must implement this method
|
|
50
|
-
# (obviously... what's the point of a command that can't be run?).
|
|
51
|
-
#
|
|
52
|
-
# +options+:: A hash containing the parsed commandline options. For
|
|
53
|
-
# example, '--foo=bar' will be converted into { :foo => 'bar'
|
|
54
|
-
# }. See the Cri::OptionParser documentation for details.
|
|
55
|
-
#
|
|
56
|
-
# +arguments+:: An array of strings representing the commandline arguments
|
|
57
|
-
# given to this command.
|
|
58
|
-
def run(options, arguments)
|
|
59
|
-
raise NotImplementedError.new("Command subclasses should override #run")
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# Returns the help text for this command.
|
|
63
|
-
def help
|
|
64
|
-
text = ''
|
|
65
|
-
|
|
66
|
-
# Append usage
|
|
67
|
-
text << usage + "\n"
|
|
68
|
-
|
|
69
|
-
# Append aliases
|
|
70
|
-
unless aliases.empty?
|
|
71
|
-
text << "\n"
|
|
72
|
-
text << "aliases: #{aliases.join(' ')}\n"
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Append short description
|
|
76
|
-
text << "\n"
|
|
77
|
-
text << short_desc + "\n"
|
|
78
|
-
|
|
79
|
-
# Append long description
|
|
80
|
-
text << "\n"
|
|
81
|
-
text << long_desc.wrap_and_indent(78, 4) + "\n"
|
|
82
|
-
|
|
83
|
-
# Append options
|
|
84
|
-
unless option_definitions.empty?
|
|
85
|
-
text << "\n"
|
|
86
|
-
text << "options:\n"
|
|
87
|
-
text << "\n"
|
|
88
|
-
option_definitions.sort { |x,y| x[:long] <=> y[:long] }.each do |opt_def|
|
|
89
|
-
text << sprintf(" -%1s --%-10s %s\n", opt_def[:short], opt_def[:long], opt_def[:desc])
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# Return text
|
|
94
|
-
text
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# Compares this command's name to the other given command's name.
|
|
98
|
-
def <=>(other)
|
|
99
|
-
self.name <=> other.name
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
end
|