tower-cli icon indicating copy to clipboard operation
tower-cli copied to clipboard

Have an explicit "exists" option for CLI entities

Open drpatelh opened this issue 2 years ago • 4 comments

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

drpatelh avatar Nov 25 '21 10:11 drpatelh

What's the use case for this?

pditommaso avatar Nov 25 '21 10:11 pditommaso

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.

drpatelh avatar Nov 25 '21 11:11 drpatelh

I have a shorter trick 😄

tw <something> list | grep <name> -c 

pditommaso avatar Nov 25 '21 11:11 pditommaso

Ok. Thanks. I will test out some solutions like this when messing around with the CLI end-to-end and update here.

drpatelh avatar Nov 25 '21 13:11 drpatelh