Crystal: update `crystal init` to handle `.`

Created on 12 Jan 2020  路  4Comments  路  Source: crystal-lang/crystal

Currently, crystal init <type> . doesn't expand the . to the current directory, which I found odd, compared to say, rails new .

I've got a PR with the feature here.

Most helpful comment

The entire logic is flawed and fails for any value other than a plain directory name without any hierarchical component. The NAME argument is used literally as value for the shard name, so crystal init lib foo/bar results in name: foo/bar.

There are several aspects to this problem:

  • config.name should be validated to match the specification for a shard name. Otherwise, crystal init should fail.
  • The first argument should always be expanded using File.expand (with home: true) and the name retrieved using File.basename, unless obviously, both NAME and DIR arguments are present.
  • Following that, the arguments usage should probably rather be specified as crystal init TYPE (DIR | NAME DIR).

All 4 comments

The entire logic is flawed and fails for any value other than a plain directory name without any hierarchical component. The NAME argument is used literally as value for the shard name, so crystal init lib foo/bar results in name: foo/bar.

There are several aspects to this problem:

  • config.name should be validated to match the specification for a shard name. Otherwise, crystal init should fail.
  • The first argument should always be expanded using File.expand (with home: true) and the name retrieved using File.basename, unless obviously, both NAME and DIR arguments are present.
  • Following that, the arguments usage should probably rather be specified as crystal init TYPE (DIR | NAME DIR).

Awesome points, didn't even know we had explict shard naming rules.

Will update the pr when i get time

Regarding the shard convention, I think it would be handy to remove crystal- prefix and .cr/-crystal suffix from dir name to determine the shard's name.

Fixed by #8681

Please open other issues/PRs for the remaining issues.

Was this page helpful?
0 / 5 - 0 ratings