2011-08-12 20:35:27 +02:00
|
|
|
Well-known options
|
|
|
|
------------------
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
The following options are well-known, and should not be used for any
|
|
|
|
other purpose:
|
2011-08-12 20:35:27 +02:00
|
|
|
|
|
|
|
-h, --help display usage and exit
|
|
|
|
-V, --version display version and exit
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
The rule of thumb with other options is that once they exist, you may
|
|
|
|
not change them, nor change how they work, nor remove them.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2017-06-18 13:31:36 -04:00
|
|
|
See Legacy options below.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
How a usage text is supposed to look
|
|
|
|
------------------------------------
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
The usage output begins with an empty line, followed by 'Usage:', and
|
|
|
|
then the synopsis on the line after that. The synopsis and option-
|
|
|
|
description lines are all indented by one space (0x40).
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
The synopsis line describes how to compose the command. Sometimes you
|
|
|
|
may need multiple synopsis lines -- this is documented separately in the
|
|
|
|
Synopsis section.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
Notations. Diamond brackets are used to mark an argument to be filled in.
|
|
|
|
Square brackets are used to mark anything that is optional, such as optional
|
|
|
|
command arguments, or optional option arguments. In the later case the '='
|
|
|
|
character is needed in front of the option argument, because one has to use
|
|
|
|
it. Three consecutive dots mean the unlimited repetition of the preceding.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
The short option is always written first, followed by the long option. They
|
|
|
|
are separated with a comma and one space. Lonely short or long options do
|
|
|
|
not affect where the writing of the option begins.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
Below, in between the snips, is an example of what the usage output should
|
2011-08-12 20:35:27 +02:00
|
|
|
look like.
|
|
|
|
|
|
|
|
-- snip
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
program [options] <file> [...]
|
|
|
|
|
2017-06-21 11:25:55 +02:00
|
|
|
Short program description, ideally one line only.
|
|
|
|
|
2011-08-12 20:35:27 +02:00
|
|
|
Options:
|
|
|
|
-n, --no-argument option does not use argument
|
2016-04-16 15:30:39 +01:00
|
|
|
--optional[=<arg>] option argument is optional
|
2011-08-12 20:35:27 +02:00
|
|
|
-r, --required <arg> option requires an argument
|
|
|
|
-z no long option
|
|
|
|
--xyzzy a long option only
|
|
|
|
-e, --extremely-long-long-option
|
|
|
|
use next line for description when needed
|
|
|
|
-l, --long-explanation an example of very verbose, and chatty option
|
|
|
|
description on two, or multiple lines, where the
|
2014-04-29 17:33:04 +02:00
|
|
|
continuation lines are indented by two spaces
|
2011-08-12 20:35:27 +02:00
|
|
|
-f, --foobar next option description resets indent
|
2011-09-17 12:52:32 +02:00
|
|
|
|
2011-08-12 20:35:27 +02:00
|
|
|
-h, --help display this help and exit
|
|
|
|
-V, --version output version information and exit
|
|
|
|
|
|
|
|
For more details see program(1).
|
|
|
|
-- snip
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
Note that there are usage-function definitions in the 'c.h' include file
|
|
|
|
which you must use. The location of an example file is mentioned at the
|
|
|
|
end of this text.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
Option descriptions
|
|
|
|
-------------------
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
An option description should not exceed the width of 80 characters. If
|
|
|
|
you need a longer description, use multiple lines and indentation.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
The description text begins from the point of the longest option plus two
|
|
|
|
spaces. In case adding a new option would necessitate a re-indentation of
|
|
|
|
the descriptions, it either has to be done, or the new option should begin
|
|
|
|
its description on the next line. Usually the later is better. The --help
|
|
|
|
and --version options do not follow this rule, since they are defined as
|
|
|
|
constants to ease translation work.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
An argument is preferably worded appropriately. For example, if an option
|
|
|
|
expects a number as argument, '<num>' is a suitable argument indicator.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
The order of the options has no special meaning, with the exception of
|
|
|
|
--help and --version which are expected to be last ones in the list.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
The last line of the usage text is either empty, or a message informing
|
|
|
|
about the manual page. For example: 'For more details see example(1).'.
|
|
|
|
Between the options and the man-page message there is an empty line.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
Usage function
|
|
|
|
--------------
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
The standard usage() function takes either stderr or stdout as an argument.
|
|
|
|
The argument will determine whether the program will exit with an error or
|
|
|
|
with success. The usage() function will never return.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
In the code all the strings with options have to start at the same position.
|
|
|
|
See here what this means:
|
2011-08-12 20:35:27 +02:00
|
|
|
|
|
|
|
fprintf(out, _(" -x[=<foo>] default foo is %s"), x);
|
|
|
|
fputs( _(" -y some text"), out);
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
Be nice to translators. One gettext entry should be one option, no more,
|
|
|
|
no less. For example:
|
docs: usage function and gettext
I made following survey which was sent to all email addresses in po/
directory that had the on-going millenium as time when translator had
been active.
There are two quite common styles to write a command usage print out,
which one you prefer?
1. Each option as separated translatable string. 18 votes
2. Or the whole thing as one big output. 1 vote
3. No preference. 1 vote
The questionaire had also free text field asking 'Why do you prefer
that?', and here are the answers.
[Separately] It is easier to follow changes with the translations. If
you change only one line or two, the big string would change to fuzzy
and I have to check the whole thing to see what was changed in the
original. If the changed line is a single string, the string to check
is a lot shorter.
[No preference] Usually, if there is no reason to separate strings,
better keep them together so that the context is obvious. In the case at
hand, it might help if in some language e.g. one translated line is too
wide for the screen. This is unlikely, but... OTOH, with this solution,
if you change one string the whole translation will be discarded until a
translator comes and updates it...
[Separately] It may be a bit harder to get the formatting right, but it
is much easier in maintenance. With one option changing, the
translator immediately sees the spot. And even with a lazy translator,
program author will have all the options translated that have not
changed at all.
[Separately] First one would be more in elegant I believe
[Separately] I prefer to have them separately because they don't form a
single text paragraph. In other words, they can be translated
separately because they are complete and separate "sentences". Of
course consistency of format and word choices need to be taken care of,
but the fact that the messages appear next to each other in the PO file
should be enough. Also if the options are not translated separately,
adding or editing one option causes the translation of all options to
become fuzzy and if for some reason it isn't checked before next
release (happens sometimes), all of them will show untranslated to the
user.
[Separately] Translations are a lot easier to update that way. If an
option is added, removed or changed, only a small amount of text
becomes fuzzy. If everything is in one big output, a lot of text
becomes fuzzy, and you have to read a lot more text to discover what
exactly changed.
[Separately] When updating a fuzzy translation, with one big output
it's very tedious and error-prone to find out the reason for fuzziness,
i.e. what actually has changed in the msgid.
[Separately] Way easier to translate, and especially to spot
translation updates when one string gets removed, added or modified.
[Separately] Makes translation memory more efficient. Some hard terms
in the list don't prevent translation of the whole block. Actually the
beginning of the strings don't need any translation ta all before []
part. Information about the context can be provided in comments or the
context parameter.
[Separately] Please consider the case when a part of string, (= msgid)
is changed. It is marked as fuzzy in the .po files, we translators
have to check whole sentences for the difference between it and
previous version.
[Separately] Every sentence must be a separate translation unit.
[One big output] for performance to ouput strings
[Separately] In the second case, if only one option changes (or a new
one is added), the translator will see as if all of the options
changed, having to find out which one of them is really new or has
actually changed. Also, if the translator has had no time to update
the string, only one of the options will be shown in the original
language (which is arguably ugly, but better than nothing for many
users).
[Separately] It's easier to translate the options separately using
translation memory.
[Separately] Easier to separate and see changes
[Separately] more translator friendly
[Separately] From the user POV I found the separeted version more
interesting because if a maintainer can't update the translation fast
enough between releases the user will still get the current translated
string with the new ones untraslated. From the translator POV the big
output will give more context information as one can see the whole
command options. With a new string added while the rest is translated
having some context can be more difficult.
[Separately] Additions to the list or changes to one options means you
don't have to check all lines each time.
So unless you have very, _very_ good reason you should not output all
usage as one big table. This implies also that when large usage output
is changed it should be split to small hunks. That may be a bit more
work once, but the next change will pay the extrawork off so never
hesitate when splitting.
Reference: http://www.surveymonkey.com/s/QKZ75HK
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-01-22 23:27:00 +00:00
|
|
|
|
|
|
|
fputs(_(" --you-there be nice\n"), out);
|
|
|
|
fputs(_(" -2 <whom> translators\n"), out);
|
2014-04-29 17:33:04 +02:00
|
|
|
fputs(_(" -t, --hey are doing a job that we probably cannot,"
|
docs: usage function and gettext
I made following survey which was sent to all email addresses in po/
directory that had the on-going millenium as time when translator had
been active.
There are two quite common styles to write a command usage print out,
which one you prefer?
1. Each option as separated translatable string. 18 votes
2. Or the whole thing as one big output. 1 vote
3. No preference. 1 vote
The questionaire had also free text field asking 'Why do you prefer
that?', and here are the answers.
[Separately] It is easier to follow changes with the translations. If
you change only one line or two, the big string would change to fuzzy
and I have to check the whole thing to see what was changed in the
original. If the changed line is a single string, the string to check
is a lot shorter.
[No preference] Usually, if there is no reason to separate strings,
better keep them together so that the context is obvious. In the case at
hand, it might help if in some language e.g. one translated line is too
wide for the screen. This is unlikely, but... OTOH, with this solution,
if you change one string the whole translation will be discarded until a
translator comes and updates it...
[Separately] It may be a bit harder to get the formatting right, but it
is much easier in maintenance. With one option changing, the
translator immediately sees the spot. And even with a lazy translator,
program author will have all the options translated that have not
changed at all.
[Separately] First one would be more in elegant I believe
[Separately] I prefer to have them separately because they don't form a
single text paragraph. In other words, they can be translated
separately because they are complete and separate "sentences". Of
course consistency of format and word choices need to be taken care of,
but the fact that the messages appear next to each other in the PO file
should be enough. Also if the options are not translated separately,
adding or editing one option causes the translation of all options to
become fuzzy and if for some reason it isn't checked before next
release (happens sometimes), all of them will show untranslated to the
user.
[Separately] Translations are a lot easier to update that way. If an
option is added, removed or changed, only a small amount of text
becomes fuzzy. If everything is in one big output, a lot of text
becomes fuzzy, and you have to read a lot more text to discover what
exactly changed.
[Separately] When updating a fuzzy translation, with one big output
it's very tedious and error-prone to find out the reason for fuzziness,
i.e. what actually has changed in the msgid.
[Separately] Way easier to translate, and especially to spot
translation updates when one string gets removed, added or modified.
[Separately] Makes translation memory more efficient. Some hard terms
in the list don't prevent translation of the whole block. Actually the
beginning of the strings don't need any translation ta all before []
part. Information about the context can be provided in comments or the
context parameter.
[Separately] Please consider the case when a part of string, (= msgid)
is changed. It is marked as fuzzy in the .po files, we translators
have to check whole sentences for the difference between it and
previous version.
[Separately] Every sentence must be a separate translation unit.
[One big output] for performance to ouput strings
[Separately] In the second case, if only one option changes (or a new
one is added), the translator will see as if all of the options
changed, having to find out which one of them is really new or has
actually changed. Also, if the translator has had no time to update
the string, only one of the options will be shown in the original
language (which is arguably ugly, but better than nothing for many
users).
[Separately] It's easier to translate the options separately using
translation memory.
[Separately] Easier to separate and see changes
[Separately] more translator friendly
[Separately] From the user POV I found the separeted version more
interesting because if a maintainer can't update the translation fast
enough between releases the user will still get the current translated
string with the new ones untraslated. From the translator POV the big
output will give more context information as one can see the whole
command options. With a new string added while the rest is translated
having some context can be more difficult.
[Separately] Additions to the list or changes to one options means you
don't have to check all lines each time.
So unless you have very, _very_ good reason you should not output all
usage as one big table. This implies also that when large usage output
is changed it should be split to small hunks. That may be a bit more
work once, but the next change will pay the extrawork off so never
hesitate when splitting.
Reference: http://www.surveymonkey.com/s/QKZ75HK
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-01-22 23:27:00 +00:00
|
|
|
" or how is your klingon?\n"), out);
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
When existing usage output is changed, and it happens to be one big text,
|
|
|
|
split it into chunks the size of one option. The extra work this will
|
|
|
|
entail for translators will pay off later, at the time of the next change,
|
|
|
|
when they will not need to search in the long fuzzy text what was changed,
|
|
|
|
where, how, and whether it was the only change.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2017-06-18 13:31:36 -04:00
|
|
|
|
2011-08-12 20:35:27 +02:00
|
|
|
Synopsis
|
|
|
|
--------
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
You may need to use multiple synopsis lines to show that a command does
|
|
|
|
fundamentally different things depending on options and/or arguments.
|
|
|
|
For example, ionice either changes the priority of a running command, or
|
|
|
|
executes a program with a defined priority. Therefore it is reasonable
|
|
|
|
to have two synopsis lines:
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
ionice [options] -p <pid> ...
|
|
|
|
ionice [options] <command> [<arg> ...]
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
Note that the synopsis is not meant to be a repetition of the options
|
|
|
|
segment. The fundamental difference in execution is a bit difficult to
|
|
|
|
define other than that usually the command author, package maintainer
|
|
|
|
or patch submitter will know when it should be done that way.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
Legacy options
|
|
|
|
--------------
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
Some commands use peculiar options and arguments. These will continue
|
|
|
|
to be supported, but anything like them will not be accepted as new
|
|
|
|
additions. A short list of examples:
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2017-06-18 13:31:36 -04:00
|
|
|
- Characters other than '-' to start an option. See '+' in 'more'.
|
|
|
|
- Using a number as an option. See '-<number>' in 'more'.
|
2014-04-29 17:33:04 +02:00
|
|
|
- Long options that start with a single '-'. See 'setterm'.
|
2017-06-18 13:31:36 -04:00
|
|
|
- '-?' is not expected to be a synonym of '--help', but is an unknown
|
|
|
|
option resulting in a suggestion to try --help due to a getopt failure.
|
2011-08-12 20:35:27 +02:00
|
|
|
|
|
|
|
|
2014-04-29 17:33:04 +02:00
|
|
|
Example file
|
|
|
|
------------
|
2011-08-12 20:35:27 +02:00
|
|
|
|
2017-06-18 13:31:36 -04:00
|
|
|
The file ./boilerplate.c is a minimal example of how to write
|
2014-04-29 17:33:04 +02:00
|
|
|
a usage function, set up option parsing, version printing and so on.
|