new_realm.ck 2.6 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. new_realm.ck
  9. Abstract:
  10. This module implements the new-realm command, used to create realms.
  11. Author:
  12. Evan Green 25-May-2017
  13. Environment:
  14. Chalk
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. from getopt import gnuGetopt;
  20. from santa.config import config;
  21. from santa.lib.realmmanager import getRealmManager;
  22. //
  23. // --------------------------------------------------------------------- Macros
  24. //
  25. //
  26. // ---------------------------------------------------------------- Definitions
  27. //
  28. //
  29. // ------------------------------------------------------ Data Type Definitions
  30. //
  31. //
  32. // ----------------------------------------------- Internal Function Prototypes
  33. //
  34. //
  35. // -------------------------------------------------------------------- Globals
  36. //
  37. var description = "Create a new working environment";
  38. var shortOptions = "h";
  39. var longOptions = [
  40. "help"
  41. ];
  42. var usage =
  43. "usage: santa new-realm [options] name...\n"
  44. "This command creates a new realm, representing a new working \n"
  45. "environment. If multiple names are specified on the command line,\n"
  46. "multiple realms will be created. Realm names that begin with an \n"
  47. "underscore are reserved for Santa.\n";
  48. //
  49. // ------------------------------------------------------------------ Functions
  50. //
  51. function
  52. command (
  53. args
  54. )
  55. /*++
  56. Routine Description:
  57. This routine implements the config command.
  58. Arguments:
  59. args - Supplies the arguments to the function.
  60. Return Value:
  61. Returns an exit code.
  62. --*/
  63. {
  64. var argc;
  65. var manager;
  66. var name;
  67. var options = gnuGetopt(args[1...-1], shortOptions, longOptions);
  68. var value;
  69. args = options[1];
  70. argc = args.length();
  71. options = options[0];
  72. for (option in options) {
  73. name = option[0];
  74. value = option[1];
  75. if ((name == "-h") || (name == "--help")) {
  76. Core.print(usage);
  77. return 1;
  78. } else {
  79. Core.raise(ValueError("Invalid option '%s'" % name));
  80. }
  81. }
  82. if (args.length() == 0) {
  83. Core.raise(ValueError("Expected a realm name"));
  84. }
  85. manager = getRealmManager();
  86. for (name in args) {
  87. manager.createRealm(name, {});
  88. }
  89. return 0;
  90. }
  91. //
  92. // --------------------------------------------------------- Internal Functions
  93. //