smallstep / cli

🧰 A zero trust swiss army knife for working with X509, OAuth, JWT, OATH OTP, etc.
https://smallstep.com/cli
Apache License 2.0
3.67k stars 255 forks source link

[Bug]: step context list should print an error to stderr and exit 1 if there are no contexts present #879

Open jdoss opened 1 year ago

jdoss commented 1 year ago

Steps to Reproduce

I am looking for a way to tell if STEPPATH is using contexts or not.

$ export STEPPATH=/tmp/tmpsteppath
$ step ca bootstrap --ca-url https://my.cool.ca.smallstep.com --fingerprint myfingerprint 
$ step context list
$ echo $?
0

If STEPPATH is not using a context step context list should output that there are no contexts present to stderr and exit 1

Your Environment

Fedora Linux 37

$ step version
Smallstep CLI/0.23.4 (linux/amd64)

Expected Behavior

$ export STEPPATH=/tmp/tmpsteppath
$ step ca bootstrap --ca-url https://my.cool.ca.smallstep.com --fingerprint myfingerprint 
$ step context list
Error: There are no contexts to list
$ echo $?
1

Actual Behavior

$ export STEPPATH=/tmp/tmpsteppath
$ step ca bootstrap --ca-url https://my.cool.ca.smallstep.com --fingerprint myfingerprint 
$ step context list
$ echo $?
0

Additional Context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

jdoss commented 1 year ago

I guess one can use step context current to test if the STEPPATH is using a context but I think should we add the same behavior to step context list

$ step context current
no context selected
$ echo $?
1