Skip to content

Commit 89a0af3

Browse files
Avoid exceptions when running pod without initialization
1 parent 4928b4b commit 89a0af3

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/pod/cli.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ def self.exit_on_failure?
1313
true
1414
end
1515

16+
def self.start(given_args = ARGV, config = {})
17+
command = given_args.first
18+
does_not_require_config = %w[version -V --version init].include?(command)
19+
pod_initialized = Dir.exist?(ENV["HOME"] + "/.config/pod")
20+
if does_not_require_config || pod_initialized
21+
super
22+
else
23+
puts "Missing config files. Run `pod init` first."
24+
end
25+
end
26+
1627
desc "version", "Displays the pod version"
1728
map %w[-V --version] => :version
1829
def version

spec/pod/cli_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require_relative "../support/test_helpers"
44

55
RSpec.describe Pod::CLI do
6-
describe "input interpretation" do
6+
describe "input interpretation", :init_pod do
77
context "when the input is invalid" do
88
it "tells the user that the command was not found" do
99
result = TestHelpers::CLI.run_cmd("pod invalid")
@@ -13,6 +13,18 @@
1313
end
1414
end
1515

16+
describe "init ensuring" do
17+
it "returns an error message when user tries to run pod without initialization" do
18+
expected_output = <<~OUTPUT
19+
Missing config files. Run `pod init` first.
20+
OUTPUT
21+
22+
result = TestHelpers::CLI.run_cmd("pod podcasts")
23+
24+
expect(result).to eq(expected_output.chomp)
25+
end
26+
end
27+
1628
describe "version command" do
1729
it "returns the pod version" do
1830
original_result = TestHelpers::CLI.run_cmd("pod version")

0 commit comments

Comments
 (0)