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.File.expand (with home: true) and the name retrieved using File.basename, unless obviously, both NAME and DIR arguments are present.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.
Most helpful comment
The entire logic is flawed and fails for any value other than a plain directory name without any hierarchical component. The
NAMEargument is used literally as value for the shard name, socrystal init lib foo/barresults inname: foo/bar.There are several aspects to this problem:
config.nameshould be validated to match the specification for a shard name. Otherwise,crystal initshould fail.File.expand(withhome: true) and the name retrieved usingFile.basename, unless obviously, bothNAMEandDIRarguments are present.crystal init TYPE (DIR | NAME DIR).