diff --git a/lib/pod/cli.rb b/lib/pod/cli.rb index ea8bc2a..694dc42 100644 --- a/lib/pod/cli.rb +++ b/lib/pod/cli.rb @@ -13,6 +13,17 @@ def self.exit_on_failure? true end + def self.start(given_args = ARGV, config = {}) + command = given_args.first + does_not_require_config = %w[version -V --version init].include?(command) + pod_initialized = Dir.exist?(ENV["HOME"] + "/.config/pod") + if does_not_require_config || pod_initialized + super + else + puts "Missing config files. Run `pod init` first." + end + end + desc "version", "Displays the pod version" map %w[-V --version] => :version def version diff --git a/spec/pod/cli_spec.rb b/spec/pod/cli_spec.rb index 8b307f8..ac33384 100644 --- a/spec/pod/cli_spec.rb +++ b/spec/pod/cli_spec.rb @@ -3,7 +3,7 @@ require_relative "../support/test_helpers" RSpec.describe Pod::CLI do - describe "input interpretation" do + describe "input interpretation", :init_pod do context "when the input is invalid" do it "tells the user that the command was not found" do result = TestHelpers::CLI.run_cmd("pod invalid") @@ -13,6 +13,18 @@ end end + describe "init ensuring" do + it "returns an error message when user tries to run pod without initialization" do + expected_output = <<~OUTPUT + Missing config files. Run `pod init` first. + OUTPUT + + result = TestHelpers::CLI.run_cmd("pod podcasts") + + expect(result).to eq(expected_output.chomp) + end + end + describe "version command" do it "returns the pod version" do original_result = TestHelpers::CLI.run_cmd("pod version")