Add --force flag to new command #1115

Merged
merged 5 commits into from May 18, 2013

Projects

None yet

3 participants

@caseylang
Contributor

As suggested in #1104, I've added a --force command to the new subcommand.

@caseylang
Contributor

I've noticed if foo && bar == false being used instead of if foo && !bar in a few places. If you prefer that, please let me know and I'll be happy to change.

@parkr parkr commented on the diff May 15, 2013
lib/jekyll/commands/new.rb
@@ -3,12 +3,12 @@
module Jekyll
module Commands
class New < Command
- def self.process(args)
+ def self.process(args, options = {})
raise ArgumentError.new('You must specify a path.') if args.empty?
new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
@parkr
parkr May 15, 2013 Member

In your tests, did args include --force?

@caseylang
caseylang May 16, 2013 Contributor

No, flags were properly separated from args. If you ran the command with only the force flag args would simply be an empty array. Commander is nice enough to ensure this in their specs.

@parkr
parkr May 16, 2013 Member

Awesome, thanks for confirming.

@mattr- mattr- commented on an outdated diff May 16, 2013
lib/jekyll/commands/new.rb
raise ArgumentError.new('You must specify a path.') if args.empty?
new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
FileUtils.mkdir_p new_blog_path
- unless Dir["#{new_blog_path}/**/*"].empty?
+ if !options[:force] && !Dir["#{new_blog_path}/**/*"].empty?
@mattr-
mattr- May 16, 2013 Member

I think I'd like to see something like this here instead:

if preserve_source_location?(new_blog_path, options)

where preserve_source_location? is something like so:

def self.preserve_source_location?(new_blog_path, options)
   !options[:force] && !Dir["#{new_blog_path}/**/*"].empty?
end

It's an additional abstraction but one that provides more clarity.

@parkr
Member
parkr commented May 17, 2013

This looks good to me. @mattr-, if everything checks out for you as well, merge it in! :)

@mattr-
Member
mattr- commented May 18, 2013

Nice work @clang1234 ! Thanks! ❤️ 🚢ed

@mattr- mattr- merged commit 7c012a9 into jekyll:master May 18, 2013

1 check passed

default The Travis CI build passed
Details
@mattr- mattr- added a commit that referenced this pull request May 18, 2013
@mattr- mattr- Update history to reflect merge of #1115 70d38c7
@caseylang
Contributor

Thanks guys! Glad I could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment