]>
Commit | Line | Data |
---|---|---|
f043759d RA |
1 | /* |
2 | * tipc. TIPC utility frontend. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * Authors: Richard Alpe <richard.alpe@ericsson.com> | |
10 | */ | |
11 | ||
12 | #include <stdio.h> | |
13 | #include <stdlib.h> | |
14 | #include <getopt.h> | |
15 | #include <unistd.h> | |
16 | ||
17 | #include "bearer.h" | |
18 | #include "link.h" | |
19 | #include "nametable.h" | |
20 | #include "socket.h" | |
21 | #include "media.h" | |
22 | #include "node.h" | |
535194a1 | 23 | #include "peer.h" |
f043759d | 24 | #include "cmdl.h" |
31f45088 | 25 | #include "utils.h" |
f043759d RA |
26 | |
27 | int help_flag; | |
1304f50a | 28 | int json; |
f043759d RA |
29 | |
30 | static void about(struct cmdl *cmdl) | |
31 | { | |
32 | fprintf(stderr, | |
33 | "Transparent Inter-Process Communication Protocol\n" | |
34 | "Usage: %s [OPTIONS] COMMAND [ARGS] ...\n" | |
35 | "\n" | |
36 | "Options:\n" | |
37 | " -h, --help \t\tPrint help for last given command\n" | |
1304f50a HL |
38 | " -j, --json \t\tJson format printouts\n" |
39 | " -p, --pretty \t\tpretty print\n" | |
f043759d RA |
40 | "\n" |
41 | "Commands:\n" | |
42 | " bearer - Show or modify bearers\n" | |
43 | " link - Show or modify links\n" | |
44 | " media - Show or modify media\n" | |
45 | " nametable - Show nametable\n" | |
46 | " node - Show or modify node related parameters\n" | |
535194a1 | 47 | " peer - Peer related operations\n" |
f043759d RA |
48 | " socket - Show sockets\n", |
49 | cmdl->argv[0]); | |
50 | } | |
51 | ||
52 | int main(int argc, char *argv[]) | |
53 | { | |
54 | int i; | |
55 | int res; | |
56 | struct cmdl cmdl; | |
57 | const struct cmd cmd = {"tipc", NULL, about}; | |
58 | struct option long_options[] = { | |
59 | {"help", no_argument, 0, 'h'}, | |
1304f50a HL |
60 | {"json", no_argument, 0, 'j'}, |
61 | {"pretty", no_argument, 0, 'p'}, | |
f043759d RA |
62 | {0, 0, 0, 0} |
63 | }; | |
64 | const struct cmd cmds[] = { | |
65 | { "bearer", cmd_bearer, cmd_bearer_help}, | |
66 | { "link", cmd_link, cmd_link_help}, | |
67 | { "media", cmd_media, cmd_media_help}, | |
68 | { "nametable", cmd_nametable, cmd_nametable_help}, | |
69 | { "node", cmd_node, cmd_node_help}, | |
535194a1 | 70 | { "peer", cmd_peer, cmd_peer_help}, |
f043759d RA |
71 | { "socket", cmd_socket, cmd_socket_help}, |
72 | { NULL } | |
73 | }; | |
74 | ||
75 | do { | |
76 | int option_index = 0; | |
77 | ||
1304f50a | 78 | i = getopt_long(argc, argv, "hjp", long_options, &option_index); |
f043759d RA |
79 | |
80 | switch (i) { | |
81 | case 'h': | |
82 | /* | |
83 | * We want the help for the last command, so we flag | |
84 | * here in order to print later. | |
85 | */ | |
86 | help_flag = 1; | |
87 | break; | |
1304f50a HL |
88 | case 'j': |
89 | /* | |
90 | * Enable json format printouts | |
91 | */ | |
92 | json = 1; | |
93 | break; | |
94 | case 'p': | |
95 | /* | |
96 | * Enable json pretty output | |
97 | */ | |
98 | pretty = 1; | |
99 | break; | |
f043759d RA |
100 | case -1: |
101 | /* End of options */ | |
102 | break; | |
103 | default: | |
104 | /* Invalid option, error msg is printed by getopts */ | |
105 | return 1; | |
106 | } | |
107 | } while (i != -1); | |
108 | ||
109 | cmdl.optind = optind; | |
110 | cmdl.argc = argc; | |
111 | cmdl.argv = argv; | |
112 | ||
113 | if ((res = run_cmd(NULL, &cmd, cmds, &cmdl, NULL)) != 0) | |
114 | return 1; | |
115 | ||
116 | return 0; | |
117 | } |