stop recursion once dir is found, add command short aliases
This commit is contained in:
parent
f754a4b3fa
commit
82ab996cb3
|
@ -8,7 +8,7 @@ require 'rubygems'
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module ProjectLocator
|
module ProjectLocator
|
||||||
def self.locate_middleman_root!
|
def self.locate_middleman_root!(args)
|
||||||
cwd = Dir.pwd
|
cwd = Dir.pwd
|
||||||
|
|
||||||
if !in_middleman_project? && !in_middleman_project_subdirectory?
|
if !in_middleman_project? && !in_middleman_project_subdirectory?
|
||||||
|
@ -17,13 +17,14 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
if in_middleman_project?
|
if in_middleman_project?
|
||||||
did_locate_middleman_project(cwd)
|
did_locate_middleman_project(cwd, args)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
Dir.chdir("..") do
|
Dir.chdir("..") do
|
||||||
# Recurse in a chdir block: if the search fails we want to be sure
|
# Recurse in a chdir block: if the search fails we want to be sure
|
||||||
# the application is generated in the original working directory.
|
# the application is generated in the original working directory.
|
||||||
locate_middleman_root! unless cwd == Dir.pwd
|
locate_middleman_root!(args) unless cwd == Dir.pwd
|
||||||
end
|
end
|
||||||
rescue SystemCallError
|
rescue SystemCallError
|
||||||
# could not chdir, no problem just return
|
# could not chdir, no problem just return
|
||||||
|
@ -37,24 +38,36 @@ module Middleman
|
||||||
File.exists?(File.join(path, 'config.rb')) || !path.root? && in_middleman_project_subdirectory?(path.parent)
|
File.exists?(File.join(path, 'config.rb')) || !path.root? && in_middleman_project_subdirectory?(path.parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.did_locate_middleman_project(path)
|
def self.did_locate_middleman_project(path, args)
|
||||||
# Set up gems listed in the Gemfile.
|
# Set up gems listed in the Gemfile.
|
||||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', path)
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', path)
|
||||||
|
|
||||||
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||||
|
|
||||||
start_cli!
|
start_cli!(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.start_cli!
|
def self.start_cli!(args)
|
||||||
require 'middleman'
|
require 'middleman'
|
||||||
Middleman::CLI.start
|
Middleman::CLI.start(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if ARGV.length < 1 || %w(server build migrate).include?(ARGV.first)
|
args = ARGV.dup
|
||||||
Middleman::ProjectLocator.locate_middleman_root!
|
|
||||||
else
|
ARG_ALIASES = {
|
||||||
Middleman::ProjectLocator.start_cli!
|
"s" => "server",
|
||||||
|
"b" => "build",
|
||||||
|
"i" => "init"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ARG_ALIASES.has_key?(args[0])
|
||||||
|
args[0] = ARG_ALIASES[args[0]]
|
||||||
|
end
|
||||||
|
|
||||||
|
if args.length < 1 || %w(server build migrate).include?(args.first)
|
||||||
|
Middleman::ProjectLocator.locate_middleman_root!(args)
|
||||||
|
else
|
||||||
|
Middleman::ProjectLocator.start_cli!(args)
|
||||||
end
|
end
|
Loading…
Reference in a new issue