From 66b74b0116744d212250e23903a9c00bee837c3d Mon Sep 17 00:00:00 2001 From: Alexandre Oliveira Date: Sun, 3 Jul 2016 12:46:07 -0300 Subject: [PATCH] Add command to generate settings docs --- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../ExtractSettingsDocsCommand.cs | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 OpenRA.Mods.Common/UtilityCommands/ExtractSettingsDocsCommand.cs diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 44c49a43f9..a517a6c0c3 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -555,6 +555,7 @@ + diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractSettingsDocsCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractSettingsDocsCommand.cs new file mode 100644 index 0000000000..7968b18e90 --- /dev/null +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractSettingsDocsCommand.cs @@ -0,0 +1,86 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Linq; + +namespace OpenRA.Mods.Common.UtilityCommands +{ + class ExtractSettingsDocsCommand : IUtilityCommand + { + public string Name { get { return "--settings-docs"; } } + + public bool ValidateArguments(string[] args) + { + return true; + } + + [Desc("Generate settings documentation in markdown format.")] + public void Run(ModData modData, string[] args) + { + Game.ModData = modData; + Console.WriteLine( + "This documentation is aimed at server administrators. It displays all settings with default values and description. " + + "Please do not edit it directly, but add new `[Desc(\"String\")]` tags to the source code. This file has been " + + "automatically generated for version {0} of OpenRA.", Game.ModData.Manifest.Mod.Version); + Console.WriteLine(); + Console.WriteLine("All settings can be changed by starting the game via a command-line parameter like `Game.Mod=ra`."); + Console.WriteLine(); + Console.WriteLine("## Location"); + Console.WriteLine("* Windows: `My Documents\\OpenRA\\settings.yaml`"); + Console.WriteLine("* Mac OS X: `~/Library/Application Support/OpenRA/settings.yaml`"); + Console.WriteLine("* Linux `~/.openra/settings.yaml`"); + Console.WriteLine(); + Console.WriteLine( + "If you create the folder `Support` relative to the OpenRA main directory, everything " + + "including settings gets stored there to aid portable installations."); + Console.WriteLine(); + + var sections = new Settings(null, new Arguments()).Sections; + sections.Add("Launch", new LaunchArguments(new Arguments(new string[0]))); + foreach (var section in sections.OrderBy(s => s.Key)) + { + var fields = section.Value.GetType().GetFields(); + if (fields.Length > 0 && fields.Where(field => field.GetCustomAttributes(false).Length > 0).Count() > 0) + Console.WriteLine("## {0}", section.Key); + else + Console.WriteLine(); + + foreach (var field in fields) + { + if (!field.HasAttribute()) + continue; + + Console.WriteLine("### {0}", field.Name); + var lines = field.GetCustomAttributes(false).SelectMany(d => d.Lines); + foreach (var line in lines) + { + Console.WriteLine("{0}", line); + Console.WriteLine(); + } + + var value = field.GetValue(section.Value); + if (value != null && !value.ToString().StartsWith("System.")) + { + Console.WriteLine("**Default Value:** {0}", value); + Console.WriteLine(); + Console.WriteLine("```yaml"); + Console.WriteLine("{0}: ", section.Key); + Console.WriteLine("\t{0}: {1}", field.Name, value); + Console.WriteLine("``` "); + } + else + Console.WriteLine(); + } + } + } + } +}