dropbox / dbxcli

A command line client for Dropbox built using the Go SDK
Other
1.06k stars 99 forks source link

Check `args` slice bounds in all commands #18

Closed waits closed 8 years ago

waits commented 8 years ago

Several commands panic when not passed enough arguments. They print an unhelpful index out of range error and a stack trace. This is undesirable for most routine error conditions.

In the same spirit as #12 I added len(args) guard clauses to the remaining commands that require arguments. They now return a helpful error explaining the arguments needed.

Example:

$ dbxcli mkdir
Error: `mkdir` requires a `directory` argument

Thoughts/questions:

$ docker pull
docker: "pull" requires 1 argument.
See 'docker pull --help'.

Usage:  docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Pull an image or a repository from a registry
diwakergupta commented 8 years ago

Merging as-is, thanks @waits! Regarding your comments, I really wish Cobra had some way to support this directly (e.g. some notion of a "validator" for each command that can check on len(args) or other validations).