Skip to content

Commit 94a3025

Browse files
authored
fix: display a warning when file exists (#81)
Merge pull request 81
1 parent f063a95 commit 94a3025

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

lib/jekyll-compose/file_creator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def file_path
2525
private
2626

2727
def validate_should_write!
28-
raise ArgumentError, "A #{file.resource_type} already exists at #{file_path}" if File.exist?(file_path) && !force
28+
return Jekyll.logger.warn "A #{file.resource_type} already exists at #{file_path}".yellow if File.exist?(file_path) && !force
2929
end
3030

3131
def ensure_directory_exists

spec/draft_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@
6363
FileUtils.touch path
6464
end
6565

66-
it "raises an error" do
67-
expect(lambda {
68-
capture_stdout { described_class.process(args) }
69-
}).to raise_error("A draft already exists at _drafts/an-existing-draft.md")
66+
it "displays a warning and abort" do
67+
output = capture_stdout { described_class.process(args) }
68+
expect(output).to include("A draft already exists at _drafts/an-existing-draft.md".yellow)
7069
end
7170

7271
it "overwrites if --force is given" do

spec/page_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@
5252
FileUtils.touch path
5353
end
5454

55-
it "raises an error" do
56-
expect(lambda {
57-
capture_stdout { described_class.process(args) }
58-
}).to raise_error("A page already exists at #{filename}")
55+
it "displays a warning" do
56+
output = capture_stdout { described_class.process(args) }
57+
expect(output).to include("A page already exists at #{filename}".yellow)
5958
end
6059

6160
it "overwrites if --force is given" do

spec/post_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@
7474
FileUtils.touch path
7575
end
7676

77-
it "raises an error" do
78-
expect(lambda {
79-
capture_stdout { described_class.process(args) }
80-
}).to raise_error("A post already exists at _posts/#{filename}")
77+
it "displays a warning" do
78+
output = capture_stdout { described_class.process(args) }
79+
expect(output).to include("A post already exists at _posts/#{filename}".yellow)
8180
end
8281

8382
it "overwrites if --force is given" do

0 commit comments

Comments
 (0)