Skip to content

Commit

Permalink
Fix NoMethodError when passing invalid path to --collection
Browse files Browse the repository at this point in the history
Before:

```console
$ bundle exec exe/typeprof smoke/simple.rb --collection=foo.yml
bundler: failed to load command: exe/typeprof (exe/typeprof)
/.../typeprof/lib/typeprof/cli.rb:108:in `parse': undefined method `exist?' for "foo.yml":String (NoMethodError)

      if !no_collection && (collection_path && !collection_path.exist?)
                                                               ^^^^^^^
```

After:

```console
$ bundle exec exe/typeprof smoke/simple.rb --collection=foo.yml
invalid option: collection path not found (foo.yml)

$ bundle exec exe/typeprof smoke/simple.rb --collection=foo.yml --no-collection
# TypeProf 0.21.7
...
```
  • Loading branch information
ybiquitous authored and mame committed May 23, 2023
1 parent e64f128 commit e8355ad
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/typeprof/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def parse(argv)
gem_rbs_features = []
show_version = false
max_sec = max_iter = nil
collection_path = RBS::Collection::Config::PATH
collection_path = nil
no_collection = false

load_path_ext = []

Expand All @@ -35,8 +36,8 @@ def parse(argv)
opt.on("--version", "Display typeprof version") { show_version = true }
opt.on("-I DIR", "Add DIR to the load/require path") {|v| load_path_ext << v }
opt.on("-r FEATURE", "Require RBS of the FEATURE gem") {|v| gem_rbs_features << v }
opt.on("--collection PATH", "File path of collection configuration") { |v| collection_path = v }
opt.on("--no-collection", "Ignore collection configuration") { collection_path = nil }
opt.on("--collection PATH", "File path of collection configuration") { |v| collection_path = Pathname(v) }
opt.on("--no-collection", "Ignore collection configuration") { no_collection = true }
opt.on("--lsp", "LSP mode") {|v| options[:lsp] = true }

opt.separator ""
Expand Down Expand Up @@ -104,6 +105,14 @@ def parse(argv)
raise OptionParser::InvalidOption.new("lsp options with non-lsp mode")
end

if !no_collection && collection_path && !collection_path.exist?
exit if show_version
raise OptionParser::InvalidOption.new("collection path not found (#{collection_path})")
end

collection_path ||= RBS::Collection::Config::PATH
collection_path = nil if no_collection

ConfigData.new(
rb_files: rb_files,
rbs_files: rbs_files,
Expand Down

0 comments on commit e8355ad

Please sign in to comment.