Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
first command line tool run
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondandy committed Dec 15, 2014
1 parent 0afdc2f commit ef3e470
Show file tree
Hide file tree
Showing 21 changed files with 190 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ UpgradeLog*.XML

/build/packed/*.nupkg
*.pubxml

/artifacts
1 change: 1 addition & 0 deletions docs/content/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`ho ho`
1 change: 1 addition & 0 deletions docs/content/junk/some-stuff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Haha
5 changes: 5 additions & 0 deletions docs/templates/_delegate.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>@Model.ShortName</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions docs/templates/_event.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>@Model.ShortName</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions docs/templates/_field.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>@Model.ShortName</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions docs/templates/_method.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>@Model.ShortName</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions docs/templates/_namespace.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>@Model.ShortName</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions docs/templates/_property.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>@Model.ShortName</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions docs/templates/_type.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>@Model.ShortName</h1>
</body>
</html>
7 changes: 5 additions & 2 deletions src/DuckyDocs.Console/DuckyDocs.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@
<Reference Include="ColoredConsole">
<HintPath>..\..\packages\ColoredConsole.0.4.0\lib\net45\ColoredConsole.dll</HintPath>
</Reference>
<Reference Include="PowerArgs">
<HintPath>..\..\packages\PowerArgs.2.3.2.0\lib\net40\PowerArgs.dll</HintPath>
<Reference Include="FluentCommandLineParser">
<HintPath>..\..\packages\FluentCommandLineParser.1.3.0\lib\net35\FluentCommandLineParser.dll</HintPath>
</Reference>
<Reference Include="Humanizer">
<HintPath>..\..\packages\Humanizer.1.31.0\lib\portable-win+net40+sl50+wp8+wpa81\Humanizer.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion src/DuckyDocs.Console/ExitCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace DuckyDocs.Console
public enum ExitCodes : int
{
LuckyDuck = 0,
QuackQuackQuackQuackQuack = 1
QuackQuackQuaaack = 1
}
}
151 changes: 131 additions & 20 deletions src/DuckyDocs.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,163 @@
using DuckyDocs.SiteBuilder;
using PowerArgs;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ColoredConsole;
using DuckyDocs.CodeDoc;
using DuckyDocs.CRef;
using DuckyDocs.SiteBuilder;
using DuckyDocs.XmlDoc;
using Fclp;
using Humanizer;

namespace DuckyDocs.Console
{
public class Program
{

[ArgExceptionBehavior(ArgExceptionPolicy.StandardExceptionHandling)]
public class ProgramArgs
{
[ArgDescription("The target assemblies to create API documentation for.")]
public string TargetAssemblies { get; set; }
public static ProgramArgs Parse(string[] args)
{
var result = new ProgramArgs();
var parser = new FluentCommandLineParser();
parser.Setup<List<string>>('a', "apitargets")
.Callback(items => result.TargetAssemblies = items)
.WithDescription("Assemblies to create documentation for.");
parser.Setup<string>('t', "templates")
.Callback(text => result.TemplatesDirectory = text)
.WithDescription("Folder containing razor templates.");
parser.Setup<List<string>>('x', "apixml")
.Callback(items => result.XmlDocLocations = items)
.WithDescription("XML doc files and folders containing them.");
parser.Setup<bool>('s', "nosplash")
.Callback(b => result.NoSplash = b)
.WithDescription("Enable to hide the splash message.");
parser.Setup<string>('o', "output")
.Callback(text => result.OutputFolder = text)
.WithDescription("The folder to output the resulting files into.");
parser.Setup<List<string>>('d', "docs")
.Callback(items => result.DocsSources = items)
.WithDescription("The documentation sources to convert to HTML.");
parser.SetupHelp("?", "help")
.Callback(help => System.Console.WriteLine(help));
parser.Parse(args);
return result;
}

[ArgDescription("Locations of XML API documentation files.")]
public string XmlDocFiles { get; set; }
public List<string> TargetAssemblies { get; set; }

[ArgDescription("Disable the splash message")]
[DefaultValue(false)]
public bool NoSplash { get; set; }
public List<string> XmlDocLocations { get; set; }

[HelpHook]
public bool Help { get; set; }
public string OutputFolder { get; set; }

public SiteBuilderRequest CreateBuilderRequest()
{
var result = new SiteBuilderRequest();
return result;
}
public List<string> DocsSources { get; set; }

public string TemplatesDirectory { get; set; }

public bool NoSplash { get; set; }
}

static int Error(string message)
{
ColorConsole.WriteLine(("[Error]: " + message).Red());
return (int)ExitCodes.QuackQuackQuaaack;
}

static int Main(string[] args)
{
var parsedArgs = Args.Parse<ProgramArgs>(args);
var parsedArgs = ProgramArgs.Parse(args);
if (parsedArgs == null)
{
return (int)ExitCodes.QuackQuackQuackQuackQuack;
return (int)ExitCodes.QuackQuackQuaaack;
}

if (!parsedArgs.NoSplash)
{
new Splash().Print();
}

if (parsedArgs.OutputFolder == null)
{
return Error("output folder is required.");
}

var outputDirectory = new DirectoryInfo(parsedArgs.OutputFolder);
if (!outputDirectory.Exists)
{
outputDirectory.Create();
Thread.Sleep(100);
}

if (parsedArgs.DocsSources != null && parsedArgs.DocsSources.Count > 0)
{
var converter = new StaticPageConverter();
foreach (var docSource in parsedArgs.DocsSources)
{
var request = new StaticPageConverterRequest {
Recursive = true,
RelativeDestination = outputDirectory.FullName,
Source = docSource
};
var result = converter.Convert(request).ToList();

ColorConsole.WriteLine("[Complete]: ".Green(), "batch content file".ToQuantity(result.Count));
}
}

if (parsedArgs.TargetAssemblies != null && parsedArgs.TargetAssemblies.Count > 0)
{
var targetAssemblies = parsedArgs.TargetAssemblies
.Select(f => Assembly.ReflectionOnlyLoadFrom(new FileInfo(f).FullName))
.ToList();
var xmlFiles = (parsedArgs.XmlDocLocations ?? Enumerable.Empty<string>())
.SelectMany(loc => {
var fi = new FileInfo(loc);
if (fi.Exists)
{
return new[] { fi };
}
var di = new DirectoryInfo(loc);
if (di.Exists)
{
return di.EnumerateFiles("*.xml");
}
return Enumerable.Empty<FileInfo>();
})
.Select(fi => new XmlAssemblyDocument(fi.FullName))
.ToList();

var repository = new ReflectionCodeDocMemberRepository(
new ReflectionCRefLookup(targetAssemblies),
xmlFiles);

var supportRepository = new MsdnCodeDocMemberRepository();

var apiOutputDirectory = new DirectoryInfo(Path.Combine(parsedArgs.OutputFolder, "api"));
if (!apiOutputDirectory.Exists)
{
apiOutputDirectory.Create();
Thread.Sleep(100);
}

var generator = new StaticApiPageGenerator {
OutputDirectory = apiOutputDirectory,
TemplateDirectory = new DirectoryInfo(parsedArgs.TemplatesDirectory ?? "./"),
TargetRepository = repository,
SupportingRepository = supportRepository
};

var results = generator.GenerateForAllTargets().ToList();

ColorConsole.WriteLine("[Complete]: ".Green(), "api doc file".ToQuantity(results.Count));
}

return (int)ExitCodes.LuckyDuck;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DuckyDocs.Console/Splash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Print()
ConsoleColor.Yellow,
ConsoleColor.Yellow,
ConsoleColor.Cyan,
ConsoleColor.DarkMagenta};
ConsoleColor.DarkGreen};
var hugeText = new string[] {
@" ____ _ ____ ",
@"| \ _ _ ___| |_ _ _ | \ ___ ___ ___ ",
Expand Down
3 changes: 2 additions & 1 deletion src/DuckyDocs.Console/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ColoredConsole" version="0.4.0" targetFramework="net45" />
<package id="PowerArgs" version="2.3.2.0" targetFramework="net45" />
<package id="FluentCommandLineParser" version="1.3.0" targetFramework="net45" />
<package id="Humanizer" version="1.31.0" targetFramework="net45" />
</packages>
1 change: 0 additions & 1 deletion src/DuckyDocs.SiteBuilder/DuckyDocs.SiteBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
</Compile>
<Compile Include="MarkdownToHtmlConverter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SiteBuilderRequest.cs" />
<Compile Include="StaticApiPageGenerator.cs" />
<Compile Include="StaticApiPageRequest.cs" />
<Compile Include="StaticBuilderRequest.cs" />
Expand Down
26 changes: 0 additions & 26 deletions src/DuckyDocs.SiteBuilder/SiteBuilderRequest.cs

This file was deleted.

7 changes: 6 additions & 1 deletion src/DuckyDocs.SiteBuilder/StaticApiPageGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public static string CreateSlugName(string cRef)

public ICodeDocMemberRepository SupportingRepository { get; set; }

public IEnumerable<FileInfo> GenerateForAllTargets(DynamicViewBag viewBag = null)
public IEnumerable<FileInfo> GenerateForAllTargets()
{
return GenerateForAllTargets((DynamicViewBag)null);
}

public IEnumerable<FileInfo> GenerateForAllTargets(DynamicViewBag viewBag)
{
viewBag = ApplyViewBag(viewBag);

Expand Down
2 changes: 1 addition & 1 deletion src/DuckyDocs.SiteBuilder/StaticBuilderRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace DuckyDocs.SiteBuilder
{
public class StaticBuilderRequest
public class StaticPageConverterRequest
{

/// <summary>
Expand Down
4 changes: 1 addition & 3 deletions src/DuckyDocs.SiteBuilder/StaticPageConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public class TemplateModel
public string ContentHtml { get; set; }
}

public string DestinationRoot { get; set; }

public IEnumerable<StaticPageBuilderResponse> Convert(StaticBuilderRequest request)
public IEnumerable<StaticPageBuilderResponse> Convert(StaticPageConverterRequest request)
{
if (request == null) throw new ArgumentNullException("request");
Contract.EndContractBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void convert_empty_directory()
{
var sourceFolder = testFolder.Directory.CreateSubdirectory("source");
var targetFolder = testFolder.Directory.CreateSubdirectory("target");
var request = new StaticBuilderRequest
var request = new StaticPageConverterRequest
{
Recursive = true,
Source = sourceFolder.FullName,
Expand All @@ -45,7 +45,7 @@ public static void convert_nested_directories()
File.WriteAllText(Path.Combine(sourceFolder.FullName, "a.md"), "# poop");
File.WriteAllText(Path.Combine(sourceFolder.FullName, "poop", "b.md"), "`poop`");
var targetFolder = testFolder.Directory.CreateSubdirectory("target");
var request = new StaticBuilderRequest
var request = new StaticPageConverterRequest
{
Recursive = true,
Source = sourceFolder.FullName,
Expand All @@ -71,7 +71,7 @@ public static void convert_with_template()
Path.Combine(sourceFolder.FullName, "_template.cshtml"),
@"<html>@Raw(Model.ContentHtml)</html>");
var targetFolder = testFolder.Directory.CreateSubdirectory("target");
var request = new StaticBuilderRequest
var request = new StaticPageConverterRequest
{
Recursive = true,
Source = sourceFolder.FullName,
Expand Down

0 comments on commit ef3e470

Please sign in to comment.