1
0

CommandLineArgs.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System.Diagnostics.CodeAnalysis;
  2. namespace Content.Packaging;
  3. public sealed class CommandLineArgs
  4. {
  5. // PJB forgib me
  6. /// <summary>
  7. /// Generate client or server.
  8. /// </summary>
  9. public bool Client { get; set; }
  10. /// <summary>
  11. /// Should we also build the relevant project.
  12. /// </summary>
  13. public bool SkipBuild { get; set; }
  14. /// <summary>
  15. /// Should we wipe the release folder or ignore it.
  16. /// </summary>
  17. public bool WipeRelease { get; set; }
  18. /// <summary>
  19. /// Platforms for server packaging.
  20. /// </summary>
  21. public List<string>? Platforms { get; set; }
  22. /// <summary>
  23. /// Use HybridACZ for server packaging.
  24. /// </summary>
  25. public bool HybridAcz { get; set; }
  26. /// <summary>
  27. /// Configuration used for when packaging the server. (Release, Debug, Tools)
  28. /// </summary>
  29. public string Configuration { get; set; }
  30. // CommandLineArgs, 3rd of her name.
  31. public static bool TryParse(IReadOnlyList<string> args, [NotNullWhen(true)] out CommandLineArgs? parsed)
  32. {
  33. parsed = null;
  34. bool? client = null;
  35. var skipBuild = false;
  36. var wipeRelease = true;
  37. var hybridAcz = false;
  38. var configuration = "Release";
  39. List<string>? platforms = null;
  40. using var enumerator = args.GetEnumerator();
  41. var i = -1;
  42. while (enumerator.MoveNext())
  43. {
  44. i++;
  45. var arg = enumerator.Current;
  46. if (i == 0)
  47. {
  48. if (arg == "client")
  49. {
  50. client = true;
  51. }
  52. else if (arg == "server")
  53. {
  54. client = false;
  55. }
  56. else
  57. {
  58. return false;
  59. }
  60. continue;
  61. }
  62. if (arg == "--skip-build")
  63. {
  64. skipBuild = true;
  65. }
  66. else if (arg == "--no-wipe-release")
  67. {
  68. wipeRelease = false;
  69. }
  70. else if (arg == "--hybrid-acz")
  71. {
  72. hybridAcz = true;
  73. }
  74. else if (arg == "--platform")
  75. {
  76. if (!enumerator.MoveNext())
  77. {
  78. Console.WriteLine("No platform provided");
  79. return false;
  80. }
  81. platforms ??= new List<string>();
  82. platforms.Add(enumerator.Current);
  83. }
  84. else if (arg == "--configuration")
  85. {
  86. if (!enumerator.MoveNext())
  87. {
  88. Console.WriteLine("No configuration provided");
  89. return false;
  90. }
  91. configuration = enumerator.Current;
  92. }
  93. else if (arg == "--help")
  94. {
  95. PrintHelp();
  96. return false;
  97. }
  98. else
  99. {
  100. Console.WriteLine("Unknown argument: {0}", arg);
  101. }
  102. }
  103. if (client == null)
  104. {
  105. Console.WriteLine("Client / server packaging unspecified.");
  106. return false;
  107. }
  108. parsed = new CommandLineArgs(client.Value, skipBuild, wipeRelease, hybridAcz, platforms, configuration);
  109. return true;
  110. }
  111. private static void PrintHelp()
  112. {
  113. Console.WriteLine(@"
  114. Usage: Content.Packaging [client/server] [options]
  115. Options:
  116. --skip-build Should we skip building the project and use what's already there.
  117. --no-wipe-release Don't wipe the release folder before creating files.
  118. --hybrid-acz Use HybridACZ for server builds.
  119. --platform Platform for server builds. Default will output several x64 targets.
  120. --configuration Configuration to use for building the server (Release, Debug, Tools). Default is Release.
  121. ");
  122. }
  123. private CommandLineArgs(
  124. bool client,
  125. bool skipBuild,
  126. bool wipeRelease,
  127. bool hybridAcz,
  128. List<string>? platforms,
  129. string configuration)
  130. {
  131. Client = client;
  132. SkipBuild = skipBuild;
  133. WipeRelease = wipeRelease;
  134. HybridAcz = hybridAcz;
  135. Platforms = platforms;
  136. Configuration = configuration;
  137. }
  138. }