diff --git a/spec/ameba/cli/cmd_spec.cr b/spec/ameba/cli/cmd_spec.cr index a412c194..624d1ad9 100644 --- a/spec/ameba/cli/cmd_spec.cr +++ b/spec/ameba/cli/cmd_spec.cr @@ -20,8 +20,14 @@ module Ameba::Cli %w(-c --config).each do |f| it "accepts #{f} flag" do - c = Cli.parse_args [f, "config.yml"] - c.config.should eq Path["config.yml"] + c = Cli.parse_args [f, "shard.yml"] + c.config.should eq Path["shard.yml"] + end + + it "raises when config file doesn't exist" do + expect_raises(ArgumentError, "Unable to find config file foo.yml") do + Cli.parse_args [f, "foo.yml"] + end end end diff --git a/src/ameba/cli/cmd.cr b/src/ameba/cli/cmd.cr index d8ce4a7e..3b06b905 100644 --- a/src/ameba/cli/cmd.cr +++ b/src/ameba/cli/cmd.cr @@ -77,6 +77,8 @@ module Ameba::Cli parser.on("-c", "--config PATH", "Specify a configuration file") do |path| + raise ArgumentError.new("Unable to find config file #{path}") if !File.exists?(path) && !opts.skip_reading_config? + opts.config = Path[path] unless path.empty? end