3

I am writing a series of CLI tools that share the same parent command, similar to programs like git.

program verb OPTIONS

One of the action verbs, install, is designed to git clone as many repositories as URLs are specified.

What is a robust and UNIX-like logical way to determine program success or failure?

  1. Good URLs > 0 → EXIT_SUCCESS
  2. Bad URLs == 0 → EXIT_SUCCESS
  3. Write number of valid URLs to standard output, then (1) or (2)
  4. Return the number of valid URLs.
  5. Other?

1 Answer 1

4

Your program should at least exit(3) EXIT_SUCCESS (i.e. 0) on success and probably EXIT_FAILURE (i.e. 1) on failure. You could copy (or be inspired by) FreeBSD sysexits.h for more failure codes (but I am not sure it is worth the effort).

Don't forget to give some message to stderr (or thru syslog(3)) for any kind of failure. From what you describes, failing to git clone even one (amongst many) repository for your install subcommand should be a failure.

The user would probably do some corrective action (e.g. correct the spelling of the faulty URL) and then repeat the same command, so you might want it to be idempotent.

Don't forget a --help option, and document any exit code outside of 0 and 1.

3
  • Thanks. Very simple approach. I see yo do not recommend returning the number of successful downloads, but rather set the exit status depending on whether the command succeeded or not. What would be a robust way to communicate the number of successful downloads then?
    – j--
    Commented Nov 9, 2015 at 6:50
  • 1
    Output to stdout, stderr or some command specified file (or file descriptor) Commented Nov 9, 2015 at 7:39
  • Thank you for the useful links and overall great advice, nevermind the bash tag. Accepted.
    – j--
    Commented Nov 14, 2015 at 5:29

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .