Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
104 lines (93 sloc) 3.91 KB
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="Newtonsoft.Json" #>
<#@ assembly name="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" #>
<#@ assembly name="$(SolutionDir)\Cake.AzCliCore\bin\Debug\netstandard2.0\Cake.AzCli.Core.dll" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="Newtonsoft.Json" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="Cake.AzCli.Core.Models" #>
<#@ import namespace="Cake.AzCli.Core.Helpers" #>
<#@ output extension=".cs" #>
using Cake.Core;
using Cake.Core.IO;
namespace Cake.AzureCli
{
<#
var cliProgram = GetAzCliHelpOutputJson();
PushIndent(" ");
WriteCliGroup(cliProgram.RootCommand);
PopIndent();
#>
}
<#+
private NameMaker NameMaker = new NameMaker();
private CommandFinder CommandFinder = new CommandFinder();
private void WriteCliGroup(CliGroup cliGroup) {
var cliGroupType = NameMaker.MakeCliGroupType(cliGroup);
WriteLine("/// <summary>");
WriteLine("/// " + cliGroup.Description);
WriteLine("/// </summary>");
WriteLine($"public sealed class {cliGroupType} : CliGroup");
WriteLine("{");
PushIndent(" ");
WriteLine($"internal {cliGroupType}(ICakeContext context) : base(context) {{ }}");
WriteLine("");
foreach (var cliCommand in cliGroup.Commands) {
var commandName = NameMaker.MakeCommandName(cliCommand);
var commandSettings = NameMaker.MakeCommandSettings(cliCommand);
var category = NameMaker.MakeCategory(cliCommand);
WriteLine("/// <summary>");
WriteLine($"/// {cliCommand.ShortDescription}");
WriteLine($"/// (aka \"{cliCommand.Parents} {cliCommand.Name}\")");
foreach (var example in cliCommand.Examples) {
WriteLine("/// <example>");
WriteLine($"/// {example.Description}");
WriteLine("/// <code>");
WriteLine($"/// {example.Example}");
WriteLine("/// </code>");
WriteLine("/// </example>");
}
WriteLine("/// </summary>");
WriteLine("/// <param name=\"context\">The context.</param>");
WriteLine("/// <param name=\"settings\">The settings.</param>");
WriteLine($"public dynamic {commandName}({commandSettings} settings) {{");
PushIndent(" ");
WriteLine("var args = new ProcessArgumentBuilder();");
WriteLine($"args.Append(\"{cliCommand.Parents} {cliCommand.Name}\");");
foreach (var argument in cliCommand.Arguments) {
var argName = NameMaker.MakeName(argument);
WriteLine($"AppendIfNonNull(args, \"{argument.Name}\", settings.{argName});");
}
WriteLine("return Execute(args, settings);");
PopIndent();
WriteLine("}");
WriteLine("");
}
foreach (var subCliGroup in cliGroup.Subgroups) {
var cliSubGroupName = NameMaker.MakeCliGroupName(subCliGroup);
var cliSubGroupType = NameMaker.MakeCliGroupType(subCliGroup);
WriteLine("/// <summary>");
WriteLine($"/// {subCliGroup.Description}");
WriteLine("/// </summary>");
WriteLine($"public {cliSubGroupType} {cliSubGroupName} => new {cliSubGroupType}(Context);");
WriteLine("");
}
PopIndent();
WriteLine("}");
WriteLine("");
foreach (var subCliGroup in cliGroup.Subgroups) {
WriteCliGroup(subCliGroup);
}
}
private CliProgram GetAzCliHelpOutputJson() {
var templateFile = new FileInfo(Host.TemplateFile);
var currentFolder = templateFile.Directory.FullName;
var azCliHelpOutputFileLocation = Path.Combine(currentFolder, "AzCliHelpOutput.min.json");
var azCliHelpOutputJson = File.ReadAllText(azCliHelpOutputFileLocation);
var cliProgram = JsonConvert.DeserializeObject<CliProgram>(azCliHelpOutputJson);
return cliProgram;
}
#>
You can’t perform that action at this time.