Skip to content

Commit

Permalink
Merge pull request #506 from crystal-ameba/accept-stdin-with-no-filename
Browse files Browse the repository at this point in the history
Allows passing single `-` argument as a means to accept file via `STDIN`
  • Loading branch information
Sija authored Nov 20, 2024
2 parents c26b5a5 + 723a738 commit 51cb88e
Show file tree
Hide file tree
Showing 2 changed files with 9 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 @@ -156,6 +156,11 @@ module Ameba::Cli
c.globs.should eq %w[source1.cr source2.cr]
end

it "accepts single '-' argument as STDIN" do
c = Cli.parse_args %w[-]
c.stdin_filename.should eq "-"
end

it "accepts one unknown arg as explain location if it has correct format" do
c = Cli.parse_args %w[source.cr:3:22]

Expand Down
5 changes: 4 additions & 1 deletion src/ameba/cli/cmd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ module Ameba::Cli
parser.on("-r", "--rules", "Show all available rules") { opts.rules = true }
parser.on("-s", "--silent", "Disable output") { opts.formatter = :silent }
parser.unknown_args do |arr|
if arr.size == 1 && arr.first.matches?(/.+:\d+:\d+/)
case
when arr.size == 1 && arr.first == "-"
opts.stdin_filename = arr.first
when arr.size == 1 && arr.first.matches?(/.+:\d+:\d+/)
configure_explain_opts(arr.first, opts)
else
opts.globs = arr unless arr.empty?
Expand Down

0 comments on commit 51cb88e

Please sign in to comment.