From 94250487ed76c64abc6bed9e58930608a168717d Mon Sep 17 00:00:00 2001 From: "Andrew G. Morgan" Date: Mon, 11 Apr 2022 10:22:21 -0700 Subject: More useful captree usage string and man page. Include more detail about command line expectations and exit status values. Signed-off-by: Andrew G. Morgan --- doc/captree.8 | 19 ++++++++++++------- goapps/captree/captree.go | 5 +++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/doc/captree.8 b/doc/captree.8 index d2c0003..86a7de3 100644 --- a/doc/captree.8 +++ b/doc/captree.8 @@ -1,15 +1,15 @@ .\" Hey, EMACS: -*- nroff -*- -.TH CAPTREE 8 "2021-09-02" +.TH CAPTREE 8 "2022-04-11" .\" Please adjust this date whenever revising the manpage. .SH NAME -captree \- display process tree capabilities +captree \- display tree of process capabilities .SH SYNOPSIS -.BR captree " [optional args] " -.IR [pid|glob-name ... ] +.BR captree " [OPTIONS] " +.RI [( pid | glob-name ") ...]" .SH DESCRIPTION .B captree displays the capabilities on the mentioned processes indicated by -.IR pid or glob-name +.IR pid " or " glob-name value(s) given on the command line. If no .I pid etc values are supplied, @@ -34,7 +34,8 @@ Optional arguments (which must precede the list of pid|glob-name values): .TP .B \-\-help -Displays usage information and exits. +Displays usage information and exits. Note, modern Go runtimes exit +with status 0 in this case, but older runtimes exit with status 2. .TP .BR \-\-verbose Displays capability sets and IAB tuples even when they are empty, or @@ -51,7 +52,11 @@ Colo[u]rs the targeted PIDs, if stdout is a TTY, in red. This option defaults to true when running via a TTY. The \fB--color\fI=false\fR argument will suppress this color. Piping the output into some other program will also suppress the use of colo[u]r. - +.SH EXIT STATUS +If the supplied target cannot be found the exit status is 1. Should an +unrecognized option be provided, the exit status is 2. Otherwise, +.B captree +exits with status 0. .SH REPORTING BUGS Please report bugs via: .TP diff --git a/goapps/captree/captree.go b/goapps/captree/captree.go index fc89b51..5313cb4 100644 --- a/goapps/captree/captree.go +++ b/goapps/captree/captree.go @@ -340,6 +340,7 @@ func findPIDs(list []string, pids map[string]*task, glob string) <-chan string { return } fmt.Printf("no process matched %q\n", glob) + os.Exit(1) }() return finds } @@ -356,6 +357,10 @@ func setDepth(pids map[string]*task, pid string) int { } func main() { + flag.Usage = func() { + fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] [pid|glob] ...\nOptions:\n", os.Args[0]) + flag.PrintDefaults() + } flag.Parse() // Honor the command line request if possible. -- cgit 1.2.3-korg