-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
thor install <uri>
to install remote thor files
The previous code suggested that this was supported, but it was not really working as expected.
- Loading branch information
1 parent
937c443
commit 439a593
Showing
2 changed files
with
70 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,6 @@ | |
require "pathname" | ||
|
||
class Thor::Runner < Thor #:nodoc: | ||
autoload :OpenURI, "open-uri" | ||
|
||
map "-T" => :list, "-i" => :install, "-u" => :update, "-v" => :version | ||
|
||
def self.banner(command, all = false, subcommand = false) | ||
|
@@ -48,22 +46,33 @@ def method_missing(meth, *args) | |
def install(name) # rubocop:disable Metrics/MethodLength | ||
initialize_thorfiles | ||
|
||
# If a directory name is provided as the argument, look for a 'main.thor' | ||
# command in said directory. | ||
begin | ||
if File.directory?(File.expand_path(name)) | ||
base = File.join(name, "main.thor") | ||
package = :directory | ||
contents = open(base, &:read) | ||
else | ||
base = name | ||
package = :file | ||
contents = open(name, &:read) | ||
is_uri = name =~ %r{^https?\://} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
deivid-rodriguez
Author
Contributor
|
||
|
||
if is_uri | ||
base = name | ||
package = :file | ||
require "open-uri" | ||
begin | ||
contents = URI.send(:open, name, &:read) # Using `send` for Ruby 2.4- support | ||
rescue OpenURI::HTTPError | ||
raise Error, "Error opening URI '#{name}'" | ||
end | ||
else | ||
# If a directory name is provided as the argument, look for a 'main.thor' | ||
# command in said directory. | ||
begin | ||
if File.directory?(File.expand_path(name)) | ||
base = File.join(name, "main.thor") | ||
package = :directory | ||
contents = open(base, &:read) | ||
else | ||
base = name | ||
package = :file | ||
contents = open(name, &:read) | ||
end | ||
rescue Errno::ENOENT | ||
raise Error, "Error opening file '#{name}'" | ||
end | ||
rescue OpenURI::HTTPError | ||
raise Error, "Error opening URI '#{name}'" | ||
rescue Errno::ENOENT | ||
raise Error, "Error opening file '#{name}'" | ||
end | ||
|
||
say "Your Thorfile contains:" | ||
|
@@ -84,7 +93,7 @@ def install(name) # rubocop:disable Metrics/MethodLength | |
as = basename if as.empty? | ||
end | ||
|
||
location = if options[:relative] || name =~ %r{^https?://} | ||
location = if options[:relative] || is_uri | ||
name | ||
else | ||
File.expand_path(name) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Should be
\A
instead of^
, in general.