]>
Commit | Line | Data |
---|---|---|
a97b307a SK |
1 | /* Please use this file as a template when introducing new command to |
2 | * util-linux package. | |
3 | * -- remove above */ | |
4 | /* | |
38d9e7c8 KZ |
5 | * SPDX-License-Identifier: GPL-2.0-or-later |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
a97b307a SK |
12 | * fixme-command-name - purpose of it |
13 | * | |
14 | * Copyright (c) 20nn Example Commercial, Inc | |
15 | * Written by Your Name <you@example.com> | |
16 | * | |
a97b307a | 17 | */ |
a97b307a SK |
18 | #include <getopt.h> |
19 | #include <stdio.h> | |
20 | #include <unistd.h> | |
21 | ||
22 | #include "c.h" | |
23 | #include "closestream.h" | |
24 | #include "nls.h" | |
25 | ||
610d0fbc WP |
26 | /* |
27 | * FIXME: remove this comment. | |
28 | * Other usage() constants that are not demonstrated below: | |
29 | * USAGE_FUNCTIONS USAGE_COMMANDS USAGE_COLUMNS | |
30 | */ | |
86be6a32 | 31 | static void __attribute__((__noreturn__)) usage(void) |
a97b307a | 32 | { |
dc05716f | 33 | fputs(USAGE_HEADER, stdout); |
bad4c729 | 34 | fprintf(stdout, _(" %s [options] file...\n"), program_invocation_short_name); |
9e258f38 | 35 | |
dc05716f | 36 | fputs(USAGE_SEPARATOR, stdout); |
bad4c729 | 37 | fputs(_("Short program description."), stdout); |
9e258f38 | 38 | |
dc05716f | 39 | fputs(USAGE_OPTIONS, stdout); |
bad4c729 MY |
40 | fputs(_(" -n, --no-argument option does not use argument"), stdout); |
41 | fputs(_(" --optional[=<arg>] option argument is optional"), stdout); | |
42 | fputs(_(" -r, --required <arg> option requires an argument"), stdout); | |
43 | fputs(_(" -z no long option"), stdout); | |
44 | fputs(_(" --xyzzy a long option only"), stdout); | |
45 | fputs(_(" -e, --extremely-long-long-option\n" | |
46 | " use next line for description when needed"), stdout); | |
47 | fputs(_(" -l, --long-explanation an example of very verbose, and chatty option\n" | |
48 | " description on two, or multiple lines, where the\n" | |
49 | " consecutive lines are intended by two spaces"), stdout); | |
50 | fputs(_(" -f, --foobar next option description resets indent"), stdout); | |
dc05716f | 51 | fputs(USAGE_SEPARATOR, stdout); |
bad4c729 MY |
52 | fprintf(stdout, USAGE_HELP_OPTIONS(25)); /* char offset to align option descriptions */ |
53 | fprintf(stdout, USAGE_MAN_TAIL("fixme-command-name(1)")); | |
86be6a32 | 54 | exit(EXIT_SUCCESS); |
a97b307a SK |
55 | } |
56 | ||
57 | int main(int argc, char **argv) | |
58 | { | |
59 | int c; | |
60 | ||
61 | enum { | |
326c5c93 SK |
62 | OPT_XYZZY = CHAR_MAX + 1, |
63 | OPT_OPTIONAL /* see howto-man-page.txt about short option */ | |
a97b307a SK |
64 | }; |
65 | static const struct option longopts[] = { | |
f636ef1f SK |
66 | { "no-argument", no_argument, NULL, 'n' }, |
67 | { "optional", optional_argument, NULL, OPT_OPTIONAL }, | |
68 | { "required", required_argument, NULL, 'r' }, | |
69 | { "extremely-long-long-option", no_argument, NULL, 'e' }, | |
70 | { "xyzzy", no_argument, NULL, OPT_XYZZY }, | |
71 | { "long-explanation", no_argument, NULL, 'l' }, | |
72 | { "foobar", no_argument, NULL, 'f' }, | |
73 | { "version", no_argument, NULL, 'V' }, | |
74 | { "help", no_argument, NULL, 'h' }, | |
87918040 | 75 | { NULL, 0, NULL, 0 } |
a97b307a SK |
76 | }; |
77 | ||
78 | setlocale(LC_ALL, ""); | |
79 | bindtextdomain(PACKAGE, LOCALEDIR); | |
80 | textdomain(PACKAGE); | |
2c308875 | 81 | close_stdout_atexit(); |
a97b307a | 82 | |
6cb55736 | 83 | while ((c = getopt_long(argc, argv, "nr:zelfVh", longopts, NULL)) != -1) |
a97b307a SK |
84 | switch (c) { |
85 | case 'n': | |
326c5c93 | 86 | case OPT_OPTIONAL: |
a97b307a | 87 | case 'r': |
6cb55736 | 88 | case 'z': |
a97b307a SK |
89 | case OPT_XYZZY: |
90 | case 'e': | |
91 | case 'l': | |
92 | case 'f': | |
93 | break; | |
94 | case 'V': | |
2c308875 | 95 | print_version(EXIT_SUCCESS); |
a97b307a | 96 | case 'h': |
86be6a32 | 97 | usage(); |
a97b307a | 98 | default: |
677ec86c | 99 | errtryhelp(EXIT_FAILURE); |
a97b307a SK |
100 | } |
101 | ||
102 | return EXIT_SUCCESS; | |
103 | } |