crystal-lang / shards

Dependency manager for the Crystal language
Other
758 stars 99 forks source link

Scripts cannot be used for subcommands on Windows #632

Open straight-shoota opened 1 month ago

straight-shoota commented 1 month ago

When invokied with a command that is not defined (say shards foo), shards tries to find a program called shards-foo and executes that. This is a simple mechanism to enable extensions of shards features outside of the main binary.

On Windows, the subcommand is required to be a binary exectuable. Scripts files (batch or PowerShell) are not supported.

Script files require a file extension in order to be considered executable in Windows shell. So the file would need to be called shards-foo.bat, but that doesn't match shards-foo.

If you explicitly use the extension as part of the subcommand name, execution still fails because shell scripts cannot be launced like executables on Windows outside a shell environment.

$ shards foobar.ps1
Unhandled exception: Error executing process: 'C:\crystal\crystal\shards-foobar.ps1': Exec format error (IO::Error)

On posix systems this all works because script files don't need an extension and can be executed directly without a shell. This should work on Windows as well.

We'll need to figure out the details, but I suppose we could look for files with script extensions as well, and if found, execute them in a shell.