]> git.ipfire.org Git - thirdparty/util-linux.git/blame_incremental - Documentation/howto-usage-function.txt
taskset: Accept 0 pid for current process
[thirdparty/util-linux.git] / Documentation / howto-usage-function.txt
... / ...
CommitLineData
1
2Example file
3------------
4
5Refer to the ./boilerplate.c example file while reading this howto.
6
7
8How a usage text is supposed to look
9------------------------------------
10
11The usage() output format is: Usage section, command description one-liner,
12Options section (see below), special sections like 'Available columns', and
13the last line is either the man page reference or an empty line. The output
14begins with, and each of the above are separated by, one empty line.
15
16The Usage section contains the synopsis line that describes how to compose
17the command. Sometimes you may need multiple synopsis lines (see below).
18
19Only the synopsis and option lines are indented. Indent is one space (0x40).
20Option lines do not use line-ending punctuation. Other sentences do.
21
22Notations: diamond brackets are used to mark an argument to be filled in;
23square brackets are used to mark anything that is optional, such as optional
24command arguments, or optional option arguments. In the later case the '='
25character is required in between the option and argument with no whitespace;
26three consecutive dots means the unlimited repetition of the preceding.
27
28The short option is always written first, followed by the long option. They
29are separated with a comma and one space. Lonely short or long options do
30not affect their alignment. That is, they must be in their respective column.
31
32Below, in between the snips, is an example of what the usage output should
33look like.
34
35-- snip
36
37Usage:
38 program [options] <file> [...]
39
40Short program description, ideally one line only.
41
42Options:
43 -n, --no-argument option does not use argument
44 --optional[=<arg>] option argument is optional
45 -r, --required <arg> option requires an argument
46 -z no long option
47 --xyzzy a long option only
48 -e, --extremely-long-long-option
49 use next line for description when needed
50 -l, --long-explanation an example of very verbose, and chatty option
51 description on two, or multiple lines, where the
52 continuation lines are indented by two spaces
53 -f, --foobar next option description resets indent
54
55 -h, --help display this help and exit
56 -V, --version output version information and exit
57
58For more details see program(1).
59-- snip
60
61
62Option descriptions
63-------------------
64
65This information also applies to other option-like arguments. That is,
66arguments starting with '-'. Such as: functions, commands, and so forth.
67
68An option description should not exceed the width of 80 characters. If
69you need a longer description, use multiple lines and indentation.
70
71The description text begins from the point of the longest option plus two
72spaces. If adding a new option would necessitate a re-indentation of the
73descriptions, it either has to be done, or the new option should begin its
74description on the next line. Usually the later is better.
75
76An argument is preferably worded appropriately. For example, if an option
77expects a number as argument, '<num>' is a suitable argument indicator.
78
79The order of the options has no special meaning, with the exception of
80--help and --version which are expected to be last ones in the list.
81
82
83Usage function
84--------------
85
86The usage() function will never return. It must only be called by -h/--help.
87All other cases use errtryhelp(EXIT_FAILURE).
88
89Section headers, man page, version, help, and other components of usage()
90have string constants defined in 'include/c.h' which must be used. See the
91example file listed at the top of this document. The help and version options
92are combined into a single macro which takes an argument for the column that
93their descriptions will begin on: USAGE_HELP_OPTIONS(<num>). This allows
94them to align properly with the other options.
95
96In the code, all option strings must start at the same position.
97See here what this means:
98
99 printf(out, _(" -x[=<foo>] default foo is %s"), x);
100 puts( _(" -y some text"), out);
101
102Be nice to translators. One gettext entry should be one option, no more,
103no less. For example:
104
105 puts(_(" --you-there be nice\n"), out);
106 puts(_(" -2 <whom> translators\n"), out);
107 puts(_(" -t, --hey are doing a job that we probably cannot,"
108 " or how is your klingon?\n"), out);
109
110When existing usage output is changed, and it happens to be one big text,
111split it into chunks the size of one option. The extra work this will entail
112for translators will pay off later; the next string change will not force a
113search of the long fuzzy text for what was changed, where, how, and whether
114it was the only change.
115
116
117Synopsis
118--------
119
120You may need to use multiple synopsis lines to show that a command does
121fundamentally different things depending on the options and/or arguments.
122For example, ionice either changes the priority of a running command, or
123executes a program with a defined priority. Therefore it is reasonable
124to have two synopsis lines:
125
126 ionice [options] -p <pid> ...
127 ionice [options] <command> [<arg> ...]
128
129Note that the synopsis is not meant to be a repetition of the options
130section. The fundamental difference in execution is a bit difficult to
131define. The command author, package maintainer or patch submitter will
132usually know when it should be done that way.
133
134