thor_dleavitt 0.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/CHANGELOG.md +139 -0
- data/LICENSE.md +20 -0
- data/README.md +35 -0
- data/Thorfile +30 -0
- data/bin/thor_dleavitt +6 -0
- data/lib/thor/actions.rb +318 -0
- data/lib/thor/actions/create_file.rb +105 -0
- data/lib/thor/actions/create_link.rb +60 -0
- data/lib/thor/actions/directory.rb +119 -0
- data/lib/thor/actions/empty_directory.rb +137 -0
- data/lib/thor/actions/file_manipulation.rb +317 -0
- data/lib/thor/actions/inject_into_file.rb +109 -0
- data/lib/thor/base.rb +654 -0
- data/lib/thor/command.rb +136 -0
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
- data/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/thor/error.rb +32 -0
- data/lib/thor/group.rb +282 -0
- data/lib/thor/invocation.rb +172 -0
- data/lib/thor/parser.rb +4 -0
- data/lib/thor/parser/argument.rb +74 -0
- data/lib/thor/parser/arguments.rb +171 -0
- data/lib/thor/parser/option.rb +121 -0
- data/lib/thor/parser/options.rb +218 -0
- data/lib/thor/rake_compat.rb +72 -0
- data/lib/thor/runner.rb +322 -0
- data/lib/thor/shell.rb +88 -0
- data/lib/thor/shell/basic.rb +422 -0
- data/lib/thor/shell/color.rb +148 -0
- data/lib/thor/shell/html.rb +127 -0
- data/lib/thor/util.rb +270 -0
- data/lib/thor/version.rb +3 -0
- data/lib/thor_dleavitt.rb +473 -0
- data/spec/actions/create_file_spec.rb +170 -0
- data/spec/actions/create_link_spec.rb +95 -0
- data/spec/actions/directory_spec.rb +169 -0
- data/spec/actions/empty_directory_spec.rb +129 -0
- data/spec/actions/file_manipulation_spec.rb +382 -0
- data/spec/actions/inject_into_file_spec.rb +135 -0
- data/spec/actions_spec.rb +331 -0
- data/spec/base_spec.rb +291 -0
- data/spec/command_spec.rb +80 -0
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
- data/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/spec/exit_condition_spec.rb +19 -0
- data/spec/fixtures/application.rb +2 -0
- data/spec/fixtures/app{1}/README +3 -0
- data/spec/fixtures/bundle/execute.rb +6 -0
- data/spec/fixtures/bundle/main.thor +1 -0
- data/spec/fixtures/command.thor +10 -0
- data/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/spec/fixtures/doc/COMMENTER +11 -0
- data/spec/fixtures/doc/README +3 -0
- data/spec/fixtures/doc/block_helper.rb +3 -0
- data/spec/fixtures/doc/config.rb +1 -0
- data/spec/fixtures/doc/config.yaml.tt +1 -0
- data/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
- data/spec/fixtures/enum.thor +10 -0
- data/spec/fixtures/group.thor +128 -0
- data/spec/fixtures/invoke.thor +118 -0
- data/spec/fixtures/path with spaces b/data/spec/fixtures/path with → spaces +0 -0
- data/spec/fixtures/preserve/script.sh +3 -0
- data/spec/fixtures/script.thor +220 -0
- data/spec/fixtures/subcommand.thor +17 -0
- data/spec/group_spec.rb +222 -0
- data/spec/helper.rb +67 -0
- data/spec/invocation_spec.rb +108 -0
- data/spec/parser/argument_spec.rb +53 -0
- data/spec/parser/arguments_spec.rb +66 -0
- data/spec/parser/option_spec.rb +202 -0
- data/spec/parser/options_spec.rb +400 -0
- data/spec/rake_compat_spec.rb +72 -0
- data/spec/register_spec.rb +197 -0
- data/spec/runner_spec.rb +241 -0
- data/spec/shell/basic_spec.rb +330 -0
- data/spec/shell/color_spec.rb +95 -0
- data/spec/shell/html_spec.rb +31 -0
- data/spec/shell_spec.rb +47 -0
- data/spec/subcommand_spec.rb +30 -0
- data/spec/thor_spec.rb +499 -0
- data/spec/util_spec.rb +196 -0
- data/thor.gemspec +24 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 55c16175abb37eb4826ab4df314c13d07da797eb
|
4
|
+
data.tar.gz: f2fee9368017ea5c8a04ebfbe7bbc94a1625df5a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 19a7f006b7acf2bf4f9333a3abe00a8b9f2bc53df88a511330eecf0173b6cf80c30c3aec9cb63f25217c43e96d4b6d3c684d2ccf1d08ffb4cf6a61b43a744c1d
|
7
|
+
data.tar.gz: f8fa87909fcf0e0ff1a46263aa8587d125c9f9ff945519008ffecf8bfabf9d23c9ebc854e436941b2d9ea2ad4a6409aff311e2ea89cc1c7ba2a841e4646c720d
|
data/.document
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
## 0.18.1, release 2013-03-30
|
2
|
+
* Revert regressions found in 0.18.0
|
3
|
+
|
4
|
+
## 0.18.0, release 2013-03-26
|
5
|
+
* Remove rake2thor
|
6
|
+
* Only display colors if output medium supports colors
|
7
|
+
* Pass parent_options to subcommands
|
8
|
+
* Fix non-dash-prefixed aliases
|
9
|
+
* Make error messages more helpful
|
10
|
+
* Rename "task" to "command"
|
11
|
+
* Add the method to allow for custom package name
|
12
|
+
|
13
|
+
## 0.17.0, release 2013-01-24
|
14
|
+
* Add better support for tasks that accept arbitrary additional arguments (e.g. things like `bundle exec`)
|
15
|
+
* Add #stop_on_unknown_option!
|
16
|
+
* Only strip from stdin.gets if it wasn't ended with EOF
|
17
|
+
* Allow "send" as a task name
|
18
|
+
* Allow passing options as arguments after "--"
|
19
|
+
* Autoload Thor::Group
|
20
|
+
|
21
|
+
## 0.16.0, release 2012-08-14
|
22
|
+
* Add enum to string arguments
|
23
|
+
|
24
|
+
## 0.15.4, release 2012-06-29
|
25
|
+
* Fix regression when destination root contains reserved regexp characters
|
26
|
+
|
27
|
+
## 0.15.3, release 2012-06-18
|
28
|
+
* Support strict_args_position! for backwards compatibility
|
29
|
+
* Escape Dir glob characters in paths
|
30
|
+
|
31
|
+
## 0.15.2, released 2012-05-07
|
32
|
+
* Added print_in_columns
|
33
|
+
* Exposed terminal_width as a public API
|
34
|
+
|
35
|
+
## 0.15.1, release 2012-05-06
|
36
|
+
* Fix Ruby 1.8 truncation bug with unicode chars
|
37
|
+
* Fix shell delegate methods to pass their block
|
38
|
+
* Don't output trailing spaces when printing the last column in a table
|
39
|
+
|
40
|
+
## 0.15, released 2012-04-29
|
41
|
+
* Alias method_options to options
|
42
|
+
* Refactor say to allow multiple colors
|
43
|
+
* Exposed error as a public API
|
44
|
+
* Exposed file_collision as a public API
|
45
|
+
* Exposed print_wrapped as a public API
|
46
|
+
* Exposed set_color as a public API
|
47
|
+
* Fix number-formatting bugs in print_table
|
48
|
+
* Fix "indent" typo in print_table
|
49
|
+
* Fix Errno::EPIPE when piping tasks to `head`
|
50
|
+
* More friendly error messages
|
51
|
+
|
52
|
+
## 0.14, released 2010-07-25
|
53
|
+
* Added CreateLink class and #link_file method
|
54
|
+
* Made Thor::Actions#run use system as default method for system calls
|
55
|
+
* Allow use of private methods from superclass as tasks
|
56
|
+
* Added mute(&block) method which allows to run block without any output
|
57
|
+
* Removed config[:pretend]
|
58
|
+
* Enabled underscores for command line switches
|
59
|
+
* Added Thor::Base.basename which is used by both Thor.banner and Thor::Group.banner
|
60
|
+
* Deprecated invoke() without arguments
|
61
|
+
* Added :only and :except to check_unknown_options
|
62
|
+
|
63
|
+
## 0.13, released 2010-02-03
|
64
|
+
* Added :lazy_default which is only triggered if a switch is given
|
65
|
+
* Added Thor::Shell::HTML
|
66
|
+
* Added subcommands
|
67
|
+
* Decoupled Thor::Group and Thor, so it's easier to vendor
|
68
|
+
* Added check_unknown_options! in case you want error messages to be raised in valid switches
|
69
|
+
* run(command) should return the results of command
|
70
|
+
|
71
|
+
## 0.12, released 2010-01-02
|
72
|
+
* Methods generated by attr_* are automatically not marked as tasks
|
73
|
+
* inject_into_file does not add the same content twice, unless :force is set
|
74
|
+
* Removed rr in favor to rspec mock framework
|
75
|
+
* Improved output for thor -T
|
76
|
+
* [#7] Do not force white color on status
|
77
|
+
* [#8] Yield a block with the filename on directory
|
78
|
+
|
79
|
+
## 0.11, released 2009-07-01
|
80
|
+
* Added a rake compatibility layer. It allows you to use spec and rdoc tasks on
|
81
|
+
Thor classes.
|
82
|
+
* BACKWARDS INCOMPATIBLE: aliases are not generated automatically anymore
|
83
|
+
since it may cause wrong behavior in the invocation system.
|
84
|
+
* thor help now show information about any class/task. All those calls are
|
85
|
+
possible:
|
86
|
+
|
87
|
+
thor help describe
|
88
|
+
thor help describe:amazing
|
89
|
+
Or even with default namespaces:
|
90
|
+
|
91
|
+
thor help :spec
|
92
|
+
* Thor::Runner now invokes the default task if none is supplied:
|
93
|
+
|
94
|
+
thor describe # invokes the default task, usually help
|
95
|
+
* Thor::Runner now works with mappings:
|
96
|
+
|
97
|
+
thor describe -h
|
98
|
+
* Added some documentation and code refactoring.
|
99
|
+
|
100
|
+
## 0.9.8, released 2008-10-20
|
101
|
+
* Fixed some tiny issues that were introduced lately.
|
102
|
+
|
103
|
+
## 0.9.7, released 2008-10-13
|
104
|
+
* Setting global method options on the initialize method works as expected:
|
105
|
+
All other tasks will accept these global options in addition to their own.
|
106
|
+
* Added 'group' notion to Thor task sets (class Thor); by default all tasks
|
107
|
+
are in the 'standard' group. Running 'thor -T' will only show the standard
|
108
|
+
tasks - adding --all will show all tasks. You can also filter on a specific
|
109
|
+
group using the --group option: thor -T --group advanced
|
110
|
+
|
111
|
+
## 0.9.6, released 2008-09-13
|
112
|
+
* Generic improvements
|
113
|
+
|
114
|
+
## 0.9.5, released 2008-08-27
|
115
|
+
* Improve Windows compatibility
|
116
|
+
* Update (incorrect) README and task.thor sample file
|
117
|
+
* Options hash is now frozen (once returned)
|
118
|
+
* Allow magic predicates on options object. For instance: `options.force?`
|
119
|
+
* Add support for :numeric type
|
120
|
+
* BACKWARDS INCOMPATIBLE: Refactor Thor::Options. You cannot access shorthand forms in options hash anymore (for instance, options[:f])
|
121
|
+
* Allow specifying optional args with default values: method_options(:user => "mislav")
|
122
|
+
* Don't write options for nil or false values. This allows, for example, turning color off when running specs.
|
123
|
+
* Exit with the status of the spec command to help CI stuff out some.
|
124
|
+
|
125
|
+
## 0.9.4, released 2008-08-13
|
126
|
+
* Try to add Windows compatibility.
|
127
|
+
* BACKWARDS INCOMPATIBLE: options hash is now accessed as a property in your class and is not passed as last argument anymore
|
128
|
+
* Allow options at the beginning of the argument list as well as the end.
|
129
|
+
* Make options available with symbol keys in addition to string keys.
|
130
|
+
* Allow true to be passed to Thor#method_options to denote a boolean option.
|
131
|
+
* If loading a thor file fails, don't give up, just print a warning and keep going.
|
132
|
+
* Make sure that we re-raise errors if they happened further down the pipe than we care about.
|
133
|
+
* Only delete the old file on updating when the installation of the new one is a success
|
134
|
+
* Make it Ruby 1.8.5 compatible.
|
135
|
+
* Don't raise an error if a boolean switch is defined multiple times.
|
136
|
+
* Thor::Options now doesn't parse through things that look like options but aren't.
|
137
|
+
* Add URI detection to install task, and make sure we don't append ".thor" to URIs
|
138
|
+
* Add rake2thor to the gem binfiles.
|
139
|
+
* Make sure local Thorfiles override system-wide ones.
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Yehuda Katz, Eric Hodel, et al.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/thor.png)](https://rubygems.org/gems/thor)
|
2
|
+
[![Build Status](https://secure.travis-ci.org/erikhuda/thor.png?branch=master)](http://travis-ci.org/erikhuda/thor)
|
3
|
+
[![Dependency Status](https://gemnasium.com/erikhuda/thor.png?travis)](https://gemnasium.com/erikhuda/thor)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/erikhuda/thor.png)](https://codeclimate.com/github/erikhuda/thor)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/erikhuda/thor/badge.png?branch=master)](https://coveralls.io/r/erikhuda/thor)
|
6
|
+
|
7
|
+
Thor
|
8
|
+
====
|
9
|
+
|
10
|
+
Description
|
11
|
+
-----------
|
12
|
+
Thor is a simple and efficient tool for building self-documenting command line
|
13
|
+
utilities. It removes the pain of parsing command line options, writing
|
14
|
+
"USAGE:" banners, and can also be used as an alternative to the [Rake][rake]
|
15
|
+
build tool. The syntax is Rake-like, so it should be familiar to most Rake
|
16
|
+
users.
|
17
|
+
|
18
|
+
[rake]: https://github.com/jimweirich/rake
|
19
|
+
|
20
|
+
Installation
|
21
|
+
------------
|
22
|
+
gem install thor
|
23
|
+
|
24
|
+
Usage and documentation
|
25
|
+
-----------------------
|
26
|
+
Please see the [wiki][] for basic usage and other documentation on using Thor. You can also checkout the [official homepage][homepage].
|
27
|
+
|
28
|
+
[wiki]: https://github.com/erikhuda/thor/wiki
|
29
|
+
[homepage]: http://whatisthor.com/
|
30
|
+
|
31
|
+
License
|
32
|
+
-------
|
33
|
+
Released under the MIT License. See the [LICENSE][] file for further details.
|
34
|
+
|
35
|
+
[license]: LICENSE.md
|
data/Thorfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
require 'thor/rake_compat'
|
6
|
+
|
7
|
+
class Default < Thor
|
8
|
+
include Thor::RakeCompat
|
9
|
+
Bundler::GemHelper.install_tasks
|
10
|
+
|
11
|
+
desc "build", "Build thor-#{Thor::VERSION}.gem into the pkg directory"
|
12
|
+
def build
|
13
|
+
Rake::Task["build"].execute
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "install", "Build and install thor-#{Thor::VERSION}.gem into system gems"
|
17
|
+
def install
|
18
|
+
Rake::Task["install"].execute
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "release", "Create tag v#{Thor::VERSION} and build and push thor-#{Thor::VERSION}.gem to Rubygems"
|
22
|
+
def release
|
23
|
+
Rake::Task["release"].execute
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "spec", "Run RSpec code examples"
|
27
|
+
def spec
|
28
|
+
exec "rspec spec"
|
29
|
+
end
|
30
|
+
end
|
data/bin/thor_dleavitt
ADDED
data/lib/thor/actions.rb
ADDED
@@ -0,0 +1,318 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'uri'
|
3
|
+
require 'thor/core_ext/io_binary_read'
|
4
|
+
require 'thor/actions/create_file'
|
5
|
+
require 'thor/actions/create_link'
|
6
|
+
require 'thor/actions/directory'
|
7
|
+
require 'thor/actions/empty_directory'
|
8
|
+
require 'thor/actions/file_manipulation'
|
9
|
+
require 'thor/actions/inject_into_file'
|
10
|
+
|
11
|
+
class Thor
|
12
|
+
module Actions
|
13
|
+
attr_accessor :behavior
|
14
|
+
|
15
|
+
def self.included(base) #:nodoc:
|
16
|
+
base.extend ClassMethods
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
# Hold source paths for one Thor instance. source_paths_for_search is the
|
21
|
+
# method responsible to gather source_paths from this current class,
|
22
|
+
# inherited paths and the source root.
|
23
|
+
#
|
24
|
+
def source_paths
|
25
|
+
@_source_paths ||= []
|
26
|
+
end
|
27
|
+
|
28
|
+
# Stores and return the source root for this class
|
29
|
+
def source_root(path=nil)
|
30
|
+
@_source_root = path if path
|
31
|
+
@_source_root
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the source paths in the following order:
|
35
|
+
#
|
36
|
+
# 1) This class source paths
|
37
|
+
# 2) Source root
|
38
|
+
# 3) Parents source paths
|
39
|
+
#
|
40
|
+
def source_paths_for_search
|
41
|
+
paths = []
|
42
|
+
paths += self.source_paths
|
43
|
+
paths << self.source_root if self.source_root
|
44
|
+
paths += from_superclass(:source_paths, [])
|
45
|
+
paths
|
46
|
+
end
|
47
|
+
|
48
|
+
# Add runtime options that help actions execution.
|
49
|
+
#
|
50
|
+
def add_runtime_options!
|
51
|
+
class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
|
52
|
+
:desc => "Overwrite files that already exist"
|
53
|
+
|
54
|
+
class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
|
55
|
+
:desc => "Run but do not make any changes"
|
56
|
+
|
57
|
+
class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
|
58
|
+
:desc => "Suppress status output"
|
59
|
+
|
60
|
+
class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
|
61
|
+
:desc => "Skip files that already exist"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Extends initializer to add more configuration options.
|
66
|
+
#
|
67
|
+
# ==== Configuration
|
68
|
+
# behavior<Symbol>:: The actions default behavior. Can be :invoke or :revoke.
|
69
|
+
# It also accepts :force, :skip and :pretend to set the behavior
|
70
|
+
# and the respective option.
|
71
|
+
#
|
72
|
+
# destination_root<String>:: The root directory needed for some actions.
|
73
|
+
#
|
74
|
+
def initialize(args=[], options={}, config={})
|
75
|
+
self.behavior = case config[:behavior].to_s
|
76
|
+
when "force", "skip"
|
77
|
+
_cleanup_options_and_set(options, config[:behavior])
|
78
|
+
:invoke
|
79
|
+
when "revoke"
|
80
|
+
:revoke
|
81
|
+
else
|
82
|
+
:invoke
|
83
|
+
end
|
84
|
+
|
85
|
+
super
|
86
|
+
self.destination_root = config[:destination_root]
|
87
|
+
end
|
88
|
+
|
89
|
+
# Wraps an action object and call it accordingly to the thor class behavior.
|
90
|
+
#
|
91
|
+
def action(instance) #:nodoc:
|
92
|
+
if behavior == :revoke
|
93
|
+
instance.revoke!
|
94
|
+
else
|
95
|
+
instance.invoke!
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns the root for this thor class (also aliased as destination root).
|
100
|
+
#
|
101
|
+
def destination_root
|
102
|
+
@destination_stack.last
|
103
|
+
end
|
104
|
+
|
105
|
+
# Sets the root for this thor class. Relatives path are added to the
|
106
|
+
# directory where the script was invoked and expanded.
|
107
|
+
#
|
108
|
+
def destination_root=(root)
|
109
|
+
@destination_stack ||= []
|
110
|
+
@destination_stack[0] = File.expand_path(root || '')
|
111
|
+
end
|
112
|
+
|
113
|
+
# Returns the given path relative to the absolute root (ie, root where
|
114
|
+
# the script started).
|
115
|
+
#
|
116
|
+
def relative_to_original_destination_root(path, remove_dot=true)
|
117
|
+
path = path.dup
|
118
|
+
if path.gsub!(@destination_stack[0], '.')
|
119
|
+
remove_dot ? (path[2..-1] || '') : path
|
120
|
+
else
|
121
|
+
path
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Holds source paths in instance so they can be manipulated.
|
126
|
+
#
|
127
|
+
def source_paths
|
128
|
+
@source_paths ||= self.class.source_paths_for_search
|
129
|
+
end
|
130
|
+
|
131
|
+
# Receives a file or directory and search for it in the source paths.
|
132
|
+
#
|
133
|
+
def find_in_source_paths(file)
|
134
|
+
relative_root = relative_to_original_destination_root(destination_root, false)
|
135
|
+
|
136
|
+
source_paths.each do |source|
|
137
|
+
source_file = File.expand_path(file, File.join(source, relative_root))
|
138
|
+
return source_file if File.exists?(source_file)
|
139
|
+
end
|
140
|
+
|
141
|
+
message = "Could not find #{file.inspect} in any of your source paths. "
|
142
|
+
|
143
|
+
unless self.class.source_root
|
144
|
+
message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
|
145
|
+
end
|
146
|
+
|
147
|
+
if source_paths.empty?
|
148
|
+
message << "Currently you have no source paths."
|
149
|
+
else
|
150
|
+
message << "Your current source paths are: \n#{source_paths.join("\n")}"
|
151
|
+
end
|
152
|
+
|
153
|
+
raise Error, message
|
154
|
+
end
|
155
|
+
|
156
|
+
# Do something in the root or on a provided subfolder. If a relative path
|
157
|
+
# is given it's referenced from the current root. The full path is yielded
|
158
|
+
# to the block you provide. The path is set back to the previous path when
|
159
|
+
# the method exits.
|
160
|
+
#
|
161
|
+
# ==== Parameters
|
162
|
+
# dir<String>:: the directory to move to.
|
163
|
+
# config<Hash>:: give :verbose => true to log and use padding.
|
164
|
+
#
|
165
|
+
def inside(dir='', config={}, &block)
|
166
|
+
verbose = config.fetch(:verbose, false)
|
167
|
+
pretend = options[:pretend]
|
168
|
+
|
169
|
+
say_status :inside, dir, verbose
|
170
|
+
shell.padding += 1 if verbose
|
171
|
+
@destination_stack.push File.expand_path(dir, destination_root)
|
172
|
+
|
173
|
+
# If the directory doesnt exist and we're not pretending
|
174
|
+
if !File.exist?(destination_root) && !pretend
|
175
|
+
FileUtils.mkdir_p(destination_root)
|
176
|
+
end
|
177
|
+
|
178
|
+
if pretend
|
179
|
+
# In pretend mode, just yield down to the block
|
180
|
+
block.arity == 1 ? yield(destination_root) : yield
|
181
|
+
else
|
182
|
+
FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
|
183
|
+
end
|
184
|
+
|
185
|
+
@destination_stack.pop
|
186
|
+
shell.padding -= 1 if verbose
|
187
|
+
end
|
188
|
+
|
189
|
+
# Goes to the root and execute the given block.
|
190
|
+
#
|
191
|
+
def in_root
|
192
|
+
inside(@destination_stack.first) { yield }
|
193
|
+
end
|
194
|
+
|
195
|
+
# Loads an external file and execute it in the instance binding.
|
196
|
+
#
|
197
|
+
# ==== Parameters
|
198
|
+
# path<String>:: The path to the file to execute. Can be a web address or
|
199
|
+
# a relative path from the source root.
|
200
|
+
#
|
201
|
+
# ==== Examples
|
202
|
+
#
|
203
|
+
# apply "http://gist.github.com/103208"
|
204
|
+
#
|
205
|
+
# apply "recipes/jquery.rb"
|
206
|
+
#
|
207
|
+
def apply(path, config={})
|
208
|
+
verbose = config.fetch(:verbose, true)
|
209
|
+
is_uri = path =~ /^https?\:\/\//
|
210
|
+
path = find_in_source_paths(path) unless is_uri
|
211
|
+
|
212
|
+
say_status :apply, path, verbose
|
213
|
+
shell.padding += 1 if verbose
|
214
|
+
|
215
|
+
if is_uri
|
216
|
+
contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read }
|
217
|
+
else
|
218
|
+
contents = open(path) {|io| io.read }
|
219
|
+
end
|
220
|
+
|
221
|
+
instance_eval(contents, path)
|
222
|
+
shell.padding -= 1 if verbose
|
223
|
+
end
|
224
|
+
|
225
|
+
# Executes a command returning the contents of the command.
|
226
|
+
#
|
227
|
+
# ==== Parameters
|
228
|
+
# command<String>:: the command to be executed.
|
229
|
+
# config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output. Specify :with
|
230
|
+
# to append an executable to command execution.
|
231
|
+
#
|
232
|
+
# ==== Example
|
233
|
+
#
|
234
|
+
# inside('vendor') do
|
235
|
+
# run('ln -s ~/edge rails')
|
236
|
+
# end
|
237
|
+
#
|
238
|
+
def run(command, config={})
|
239
|
+
return unless behavior == :invoke
|
240
|
+
|
241
|
+
destination = relative_to_original_destination_root(destination_root, false)
|
242
|
+
desc = "#{command} from #{destination.inspect}"
|
243
|
+
|
244
|
+
if config[:with]
|
245
|
+
desc = "#{File.basename(config[:with].to_s)} #{desc}"
|
246
|
+
command = "#{config[:with]} #{command}"
|
247
|
+
end
|
248
|
+
|
249
|
+
say_status :run, desc, config.fetch(:verbose, true)
|
250
|
+
|
251
|
+
unless options[:pretend]
|
252
|
+
config[:capture] ? `#{command}` : system("#{command}")
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
# Executes a ruby script (taking into account WIN32 platform quirks).
|
257
|
+
#
|
258
|
+
# ==== Parameters
|
259
|
+
# command<String>:: the command to be executed.
|
260
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
261
|
+
#
|
262
|
+
def run_ruby_script(command, config={})
|
263
|
+
return unless behavior == :invoke
|
264
|
+
run command, config.merge(:with => Thor::Util.ruby_command)
|
265
|
+
end
|
266
|
+
|
267
|
+
# Run a thor command. A hash of options can be given and it's converted to
|
268
|
+
# switches.
|
269
|
+
#
|
270
|
+
# ==== Parameters
|
271
|
+
# command<String>:: the command to be invoked
|
272
|
+
# args<Array>:: arguments to the command
|
273
|
+
# config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output.
|
274
|
+
# Other options are given as parameter to Thor.
|
275
|
+
#
|
276
|
+
#
|
277
|
+
# ==== Examples
|
278
|
+
#
|
279
|
+
# thor :install, "http://gist.github.com/103208"
|
280
|
+
# #=> thor install http://gist.github.com/103208
|
281
|
+
#
|
282
|
+
# thor :list, :all => true, :substring => 'rails'
|
283
|
+
# #=> thor list --all --substring=rails
|
284
|
+
#
|
285
|
+
def thor(command, *args)
|
286
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
287
|
+
verbose = config.key?(:verbose) ? config.delete(:verbose) : true
|
288
|
+
pretend = config.key?(:pretend) ? config.delete(:pretend) : false
|
289
|
+
capture = config.key?(:capture) ? config.delete(:capture) : false
|
290
|
+
|
291
|
+
args.unshift(command)
|
292
|
+
args.push Thor::Options.to_switches(config)
|
293
|
+
command = args.join(' ').strip
|
294
|
+
|
295
|
+
run command, :with => :thor, :verbose => verbose, :pretend => pretend, :capture => capture
|
296
|
+
end
|
297
|
+
|
298
|
+
protected
|
299
|
+
|
300
|
+
# Allow current root to be shared between invocations.
|
301
|
+
#
|
302
|
+
def _shared_configuration #:nodoc:
|
303
|
+
super.merge!(:destination_root => self.destination_root)
|
304
|
+
end
|
305
|
+
|
306
|
+
def _cleanup_options_and_set(options, key) #:nodoc:
|
307
|
+
case options
|
308
|
+
when Array
|
309
|
+
%w(--force -f --skip -s).each { |i| options.delete(i) }
|
310
|
+
options << "--#{key}"
|
311
|
+
when Hash
|
312
|
+
[:force, :skip, "force", "skip"].each { |i| options.delete(i) }
|
313
|
+
options.merge!(key => true)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
end
|
318
|
+
end
|