Skip to content

Commit

Permalink
Merge pull request #515 from crystal-ameba/skip-autocorrection-for-stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija authored Nov 25, 2024
2 parents 51cb88e + ea258c1 commit f72d295
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions spec/ameba/cli/cmd_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ module Ameba::Cli
end
end

it "accepts --stdin-filename flag" do
c = Cli.parse_args %w[--stdin-filename foo.cr]
c.stdin_filename.should eq "foo.cr"
end

it "accepts --only flag" do
c = Cli.parse_args ["--only", "RULE1,RULE2"]
c.only.should eq %w[RULE1 RULE2]
Expand Down
8 changes: 7 additions & 1 deletion src/ameba/cli/cmd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ require "option_parser"
module Ameba::Cli
extend self

# ameba:disable Metrics/CyclomaticComplexity
def run(args = ARGV) : Nil
opts = parse_args args
location_to_explain = opts.location_to_explain
stdin_filename = opts.stdin_filename
autocorrect = opts.autocorrect?

if location_to_explain && autocorrect
raise "Invalid usage: Cannot explain an issue and autocorrect at the same time."
end

if stdin_filename && autocorrect
raise "Invalid usage: Cannot autocorrect from stdin."
end

config = Config.load opts.config, opts.colors?, opts.skip_reading_config?
config.autocorrect = autocorrect
config.stdin_filename = opts.stdin_filename
config.stdin_filename = stdin_filename

if globs = opts.globs
config.globs = globs
Expand Down

0 comments on commit f72d295

Please sign in to comment.