list_realms.ck 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*++
  2. Copyright (c) 2017 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. list_realms.ck
  9. Abstract:
  10. This module implements the list-realms command, used to enumerate the list
  11. of created.
  12. Author:
  13. Evan Green 1-Jun-2017
  14. Environment:
  15. Chalk
  16. --*/
  17. //
  18. // ------------------------------------------------------------------- Includes
  19. //
  20. from getopt import gnuGetopt;
  21. from santa.config import config;
  22. from santa.lib.realmmanager import getRealmManager;
  23. //
  24. // --------------------------------------------------------------------- Macros
  25. //
  26. //
  27. // ---------------------------------------------------------------- Definitions
  28. //
  29. //
  30. // ------------------------------------------------------ Data Type Definitions
  31. //
  32. //
  33. // ----------------------------------------------- Internal Function Prototypes
  34. //
  35. //
  36. // -------------------------------------------------------------------- Globals
  37. //
  38. var description = "List the existing realms";
  39. var shortOptions = "h";
  40. var longOptions = [
  41. "help"
  42. ];
  43. var usage =
  44. "usage: santa list-realms [options]\n"
  45. "This command prints a list of the realms that have been created.\n";
  46. //
  47. // ------------------------------------------------------------------ Functions
  48. //
  49. function
  50. command (
  51. args
  52. )
  53. /*++
  54. Routine Description:
  55. This routine implements the config command.
  56. Arguments:
  57. args - Supplies the arguments to the function.
  58. Return Value:
  59. Returns an exit code.
  60. --*/
  61. {
  62. var argc;
  63. var manager;
  64. var name;
  65. var options = gnuGetopt(args[1...-1], shortOptions, longOptions);
  66. var realmList;
  67. var value;
  68. args = options[1];
  69. argc = args.length();
  70. options = options[0];
  71. for (option in options) {
  72. name = option[0];
  73. value = option[1];
  74. if ((name == "-h") || (name == "--help")) {
  75. Core.print(usage);
  76. return 1;
  77. } else {
  78. Core.raise(ValueError("Invalid option '%s'" % name));
  79. }
  80. }
  81. if (args.length() != 0) {
  82. Core.raise(ValueError("Expected no arguments"));
  83. }
  84. manager = getRealmManager();
  85. realmList = manager.enumerateRealms();
  86. for (name in realmList) {
  87. Core.print(name);
  88. }
  89. return 0;
  90. }
  91. //
  92. // --------------------------------------------------------- Internal Functions
  93. //