Open theduke opened 5 years ago
Git's approach is
gist = "!/bin/sh -c 'git add --all . && git commit -m x && git push'"
I think the special-case is a string beginning with !
. We could do the same with aliases.
The challenge is what syntax do you support. Bonus points for cross platform.
deno_task_shell and duckscript would be two options.;
I see the integration of an additional scripting language for this functionality as too costly for the benefits provided. Despite the cross-platform bonuses, this solution increases bulkiness, reduces maintainability, and is less flexible and straightforward compared to alternatives. One of the more flexible and simple alternatives is passing values in a [script]
object as script arguments to sh
, cmd.exe
, and other shells.
The cross-platform issue can be addressed by utilizing nested objects combined with shell settings:
[alias]
# Keeping `alias` and `script` separate avoids the need for less obvious conventions like `!`
[script]
greet = "echo -n 'Hello, ' && echo 'developer!'"
[script.powershell]
# Acts as a fallback for systems where the default shell is not found,
# and when the script was launched in PowerShell
greet = "Write-Host -NoNewline 'Hello, '; if ($?) { Write-Host 'developer!' }"
[shell]
default = "sh"
The
[alias]
configuration is very useful.It would be even more useful if there was a way to not only define aliases for
cargo
, but to run arbitrary scripts. It's a shame thatalias
doesn't allow this already. I'm therefore proposing to add a new feature:script
s.I'm imagining something like how npm works, where you can define arbitrary scripts in
package.json
that can be executed withnpm NAME
ornpm run NAME
(for conflicts). This is very widely used in the JS ecosystem and a great convenience utility.It would allow a unified way to execute project-related convenience scripts, etc.
EG:
.cargo/config:
Disambiguation could be enabled by the
cargo script
command, eg :cargo script publish && cargo deploy
.Scripts would have the lowest priority, after built in commands, aliases and external binaries. I'd prefer them to have higher priority than global aliases and extension binaries, but that would be backwards incompatible.