Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing single - argument as a means to accept file via STDIN #506

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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