tower-cli
tower-cli copied to clipboard
Have an explicit "exists" option for CLI entities
It would be nice to have an exists
sub-command for all of the different entities on the CLI e.g. credentials
, compute-envs
that outputs 0
/ 1
depending on the outcome? Would be awesome for scripting purposes e.g.
if ! tw credentials exists -i kkdevaka ; then
echo "NO COMPUTE ENV NO CRY"
else
echo "COMPUTE IT!"
fi
@jordeu suggested that this is possible with the snippet below but I think it would be more intuitive having a separate sub-command to avoid having to wrestle with bash redirection
if ! tw compute-envs view -i kkdevaka 2>1 1> /dev/null; then
echo "NO COMPUTE ENV NO CRY"
else
echo "COMPUTE IT!"
fi
What's the use case for this?
When writing and re-running a bash script or any other type of end-to-end script we can check whether these entities exist dynamically and perform the appropriate downstream steps. e.g.
if a compute environment doesn't exist then create one if a pipeline doesn't exist in the launchpad then create one etc
I was manually commenting out code to avoid re-running sections in an end-to-end script and in the end decided to use if false; then
logic to stop running a block of code when creating the different entities.
I have a shorter trick 😄
tw <something> list | grep <name> -c
Ok. Thanks. I will test out some solutions like this when messing around with the CLI end-to-end and update here.