You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.2 KiB

  1. From 26b77b7cdc70beddc68507f74372a4e2815720f0 Mon Sep 17 00:00:00 2001
  2. From: Yousong Zhou <yszhou4tech@gmail.com>
  3. Date: Sun, 17 May 2015 10:53:44 +0800
  4. Subject: [PATCH 210/210] xl2tpd-control: show all available commands in
  5. --help.
  6. ---
  7. xl2tpd-control.c | 63 ++++++++++++++++++++++++++++++++++++++----------------
  8. 1 file changed, 44 insertions(+), 19 deletions(-)
  9. diff --git a/xl2tpd-control.c b/xl2tpd-control.c
  10. index 6b08850..b98ff24 100644
  11. --- a/xl2tpd-control.c
  12. +++ b/xl2tpd-control.c
  13. @@ -51,6 +51,7 @@ struct command_t
  14. char *name;
  15. int (*handler) (FILE*, char* tunnel, int optc, char *optv[]);
  16. int requires_tunnel;
  17. + char *help;
  18. };
  19. int command_add_lac (FILE*, char* tunnel, int optc, char *optv[]);
  20. @@ -65,13 +66,29 @@ int command_available (FILE*, char* tunnel, int optc, char *optv[]);
  21. struct command_t commands[] = {
  22. /* Keep this command mapping for backwards compat */
  23. - {"add", &command_add_lac, TUNNEL_REQUIRED},
  24. - {"connect", &command_connect_lac, TUNNEL_REQUIRED},
  25. - {"disconnect", &command_disconnect_lac, TUNNEL_REQUIRED},
  26. - {"remove", &command_remove_lac, TUNNEL_REQUIRED},
  27. + {"add", &command_add_lac, TUNNEL_REQUIRED,
  28. + "\tadd\tadds new or modify existing lac configuration.\n"
  29. + "\t\tConfiguration must be specified as command options in\n"
  30. + "\t\t<key>=<value> pairs format.\n"
  31. + "\t\tSee available options in xl2tpd.conf(5)\n"
  32. + },
  33. + {"connect", &command_connect_lac, TUNNEL_REQUIRED,
  34. + "\tconnect\ttries to activate the tunnel.\n"
  35. + "\t\tUsername and secret for the tunnel can be passed as\n"
  36. + "\t\tcommand options.\n"
  37. + },
  38. + {"disconnect", &command_disconnect_lac, TUNNEL_REQUIRED,
  39. + "\tdisconnect\tdisconnects the tunnel.\n"
  40. + },
  41. + {"remove", &command_remove_lac, TUNNEL_REQUIRED,
  42. + "\tremove\tremoves lac configuration from xl2tpd.\n"
  43. + "\t\txl2tpd disconnects the tunnel before removing.\n"
  44. + },
  45. /* LAC commands */
  46. - {"add-lac", &command_add_lac, TUNNEL_REQUIRED},
  47. + {"add-lac", &command_add_lac, TUNNEL_REQUIRED,
  48. + "\tadd-lns\tadds new or modify existing lns configuration.\n"
  49. + },
  50. {"connect-lac", &command_connect_lac, TUNNEL_REQUIRED},
  51. {"disconnect-lac", &command_disconnect_lac, TUNNEL_REQUIRED},
  52. {"remove-lac", &command_remove_lac, TUNNEL_REQUIRED},
  53. @@ -89,36 +106,44 @@ struct command_t commands[] = {
  54. void usage()
  55. {
  56. + int i;
  57. +
  58. printf ("\nxl2tpd server version %s\n", SERVER_VERSION);
  59. printf ("Usage: xl2tpd-control [-c <PATH>] <command> <tunnel name> [<COMMAND OPTIONS>]\n"
  60. "\n"
  61. " -c\tspecifies xl2tpd control file\n"
  62. " -d\tspecify xl2tpd-control to run in debug mode\n"
  63. "--help\tshows extended help\n"
  64. - "Available commands: add, connect, disconnect, remove, add-lns\n"
  65. );
  66. +
  67. + printf ("Available commands: ");
  68. + for (i = 0; commands[i].name; i++) {
  69. + struct command_t *command = &commands[i];
  70. + int last = command[1].name == NULL;
  71. +
  72. + printf ("%s%s", command->name, !last ? ", " : "\n");
  73. + }
  74. }
  75. void help()
  76. {
  77. + int i;
  78. +
  79. usage();
  80. printf (
  81. "\n"
  82. "Commands help:\n"
  83. - "\tadd\tadds new or modify existing lac configuration.\n"
  84. - "\t\tConfiguration must be specified as command options in\n"
  85. - "\t\t<key>=<value> pairs format.\n"
  86. - "\t\tSee available options in xl2tpd.conf(5)\n"
  87. - "\tconnect\ttries to activate the tunnel.\n"
  88. - "\t\tUsername and secret for the tunnel can be passed as\n"
  89. - "\t\tcommand options.\n"
  90. - "\tdisconnect\tdisconnects the tunnel.\n"
  91. - "\tremove\tremoves lac configuration from xl2tpd.\n"
  92. - "\t\txl2tpd disconnects the tunnel before removing.\n"
  93. - "\n"
  94. - "\tadd-lns\tadds new or modify existing lns configuration.\n"
  95. - "See xl2tpd-control man page for more help\n"
  96. );
  97. +
  98. + for (i = 0; commands[i].name; i++) {
  99. + struct command_t *command = &commands[i];
  100. +
  101. + if (!command->help)
  102. + continue;
  103. + printf ("%s", command->help);
  104. + }
  105. + /*FIXME Ha! there is currently no manpage for xl2tpd-control */
  106. + printf ("See xl2tpd-control man page for more help\n");
  107. }
  108. void cleanup(void)
  109. --
  110. 1.7.10.4