How do you check if a command exists on windows? #1019
-
Hi there, first of all thanks for this wonderful tool! I'm mostly a linux user, but some of my colleagues prefer to work on windows, so I'm trying to keep my tools as cross-platform as possible. I would like to add a How do you check if a command already exists on windows/powershell? I tried to use Am I missing something here? Here is a minimal example: version: '3'
tasks:
install:package:
label: 'install:{{.PACKAGE_NAME}}'
vars:
PACKAGE_NAME: '{{.PACKAGE_NAME}}'
COMMAND_NAME: '{{default .PACKAGE_NAME .COMMAND_NAME}}'
cmds:
- "pip install {{.PACKAGE_NAME}}"
status:
- '{{if eq OS "windows"}}if(Get-Command {{.COMMAND_NAME}}) {Exit 0} else {Exit 1}{{else}}command -v {{.COMMAND_NAME}}{{end}}'
install:pre-commit:
cmds:
- task: install:package
vars:
PACKAGE_NAME: pre-commit
init:pre-commit:
deps:
- install:pre-commit
cmds:
- pre-commit install
lint:
deps:
- init:pre-commit
cmds:
- pre-commit run --all |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I'm not on a Windows machine ATM to try things out. This made me realize, though, that the |
Beta Was this translation helpful? Give feedback.
-
Nevermind, as I stated in the reply to @andreynering , the builtin I suppose I overlooked the explanation of the sh interpreter in the Getting Started section, and directly went to find a substitute for the command 😅 Thanks again for this great tool! |
Beta Was this translation helpful? Give feedback.
Nevermind, as I stated in the reply to @andreynering , the builtin
command -v
works on windows and I didn't even try it.I suppose I overlooked the explanation of the sh interpreter in the Getting Started section, and directly went to find a substitute for the command 😅
Thanks again for this great tool!