Merge pull request #1115 from clang1234/master
Add --force flag to new command
This commit is contained in:
commit
7c012a9e0c
|
@ -37,8 +37,10 @@ command :new do |c|
|
||||||
c.syntax = 'jekyll new PATH'
|
c.syntax = 'jekyll new PATH'
|
||||||
c.description = 'Creates a new Jekyll site scaffold in PATH'
|
c.description = 'Creates a new Jekyll site scaffold in PATH'
|
||||||
|
|
||||||
|
c.option '--force', 'Force creation even if PATH already exists'
|
||||||
|
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
Jekyll::Commands::New.process(args)
|
Jekyll::Commands::New.process(args, options.__hash__)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@ require 'erb'
|
||||||
module Jekyll
|
module Jekyll
|
||||||
module Commands
|
module Commands
|
||||||
class New < Command
|
class New < Command
|
||||||
def self.process(args)
|
def self.process(args, options = {})
|
||||||
raise ArgumentError.new('You must specify a path.') if args.empty?
|
raise ArgumentError.new('You must specify a path.') if args.empty?
|
||||||
|
|
||||||
new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
|
new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
|
||||||
FileUtils.mkdir_p new_blog_path
|
FileUtils.mkdir_p new_blog_path
|
||||||
unless Dir["#{new_blog_path}/**/*"].empty?
|
if preserve_source_location?(new_blog_path, options)
|
||||||
Jekyll::Stevenson.error "Conflict:", "#{new_blog_path} exists and is not empty."
|
Jekyll::Stevenson.error "Conflict:", "#{new_blog_path} exists and is not empty."
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
|
@ -33,6 +33,11 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def self.preserve_source_location?(path, options)
|
||||||
|
!options[:force] && !Dir["#{path}/**/*"].empty?
|
||||||
|
end
|
||||||
|
|
||||||
def self.create_sample_files(path)
|
def self.create_sample_files(path)
|
||||||
FileUtils.cp_r site_template + '/.', path
|
FileUtils.cp_r site_template + '/.', path
|
||||||
FileUtils.rm File.expand_path(scaffold_path, path)
|
FileUtils.rm File.expand_path(scaffold_path, path)
|
||||||
|
|
Loading…
Reference in New Issue