Skip to content

Commit

Permalink
Added URI path formatting option
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSWolf committed Jan 5, 2014
1 parent 7734255 commit 84ed8e4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
6 changes: 3 additions & 3 deletions MoaiUtils/CreateApiDescription/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class Configuration {
HelpText = "The output directory where the code completion file(s) will be created")]
public string OutputDirectory { get; set; }

[Option("fullPath", DefaultValue = false,
HelpText = "Show full file paths in messages (rather than relative paths)")]
public bool FullPathInMessages { get; set; }
[Option("pathFormat",
HelpText = "Determines how file paths will be displayed in messages. Valid options are Absolute (default), Relative (shorter), or URI (for clickable links in some editors).")]
public PathFormat MessagePathFormat { get; set; }
}
}
1 change: 1 addition & 0 deletions MoaiUtils/CreateApiDescription/CreateApiDescription.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Compile Include="CodeGraph\MoaiInParameter.cs" />
<Compile Include="CodeGraph\MoaiOutParameter.cs" />
<Compile Include="MoaiLuaObject.cs" />
<Compile Include="PathFormat.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CompactSignature.cs" />
Expand Down
23 changes: 17 additions & 6 deletions MoaiUtils/CreateApiDescription/FilePosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,37 @@

namespace MoaiUtils.CreateApiDescription {
public class FilePosition : IComparable {
public FilePosition(FileInfo fileInfo, DirectoryInfo rootDirectory, bool printFullPath) {
public FilePosition(FileInfo fileInfo, DirectoryInfo rootDirectory, PathFormat messagePathFormat) {
FileInfo = fileInfo;
RootDirectory = rootDirectory;
PrintFullPath = printFullPath;
MessagePathFormat = messagePathFormat;
}

public FileInfo FileInfo { get; private set; }
public DirectoryInfo RootDirectory { get; private set; }
public bool PrintFullPath { get; private set; }
public PathFormat MessagePathFormat { get; private set; }

public string FilePath {
get { return PrintFullPath ? FileInfo.FullName : FileInfo.RelativeTo(RootDirectory); }
get {
switch (MessagePathFormat) {
case PathFormat.Absolute:
return FileInfo.FullName;
case PathFormat.Relative:
return FileInfo.RelativeTo(RootDirectory);
case PathFormat.URI:
return new Uri(FileInfo.FullName).AbsoluteUri;
default:
throw new ArgumentOutOfRangeException();
}
}
}

public override string ToString() {
return FileDescription;
}

protected string FileDescription {
get { return string.Format("file '{0}'", FilePath); }
get { return string.Format("file {0}", FilePath); }
}

#region Equality members
Expand All @@ -47,7 +58,7 @@ public int CompareTo(object obj) {

public class TypePosition : FilePosition {
public TypePosition(FilePosition filePosition, string typeName)
: base(filePosition.FileInfo, filePosition.RootDirectory, filePosition.PrintFullPath) {
: base(filePosition.FileInfo, filePosition.RootDirectory, filePosition.MessagePathFormat) {
TypeName = typeName;
}

Expand Down
10 changes: 5 additions & 5 deletions MoaiUtils/CreateApiDescription/MoaiCodeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MoaiCodeParser {

private Dictionary<string, MoaiType> typesByName;

public void Parse(DirectoryInfo moaiSourceDirectory, bool fullPathInMessages) {
public void Parse(DirectoryInfo moaiSourceDirectory, PathFormat messagePathFormat) {
// Check that the input directory looks like the Moai src directory
if (!moaiSourceDirectory.GetDirectoryInfo("moai-core").Exists) {
throw new ApplicationException(string.Format("Path '{0}' does not appear to be the 'src' directory of a Moai source copy.", moaiSourceDirectory));
Expand All @@ -30,12 +30,12 @@ public void Parse(DirectoryInfo moaiSourceDirectory, bool fullPathInMessages) {

// Parse Moai types and store them by type name
log.Info("Parsing Moai types.");
ParseMoaiCodeFiles(moaiSourceDirectory, fullPathInMessages);
ParseMoaiCodeFiles(moaiSourceDirectory, messagePathFormat);

// MOAILuaObject is not documented, probably because it would mess up
// the Doxygen-generated documentation. Use dummy code instead.
log.Info("Adding hard-coded documentation for MoaiLuaObject base class.");
FilePosition dummyFilePosition = new FilePosition(new FileInfo("MoaiLuaObject dummy code"), new DirectoryInfo("."), printFullPath: false);
FilePosition dummyFilePosition = new FilePosition(new FileInfo("MoaiLuaObject dummy code"), new DirectoryInfo("."), messagePathFormat);
ParseMoaiFile(MoaiLuaObject.DummyCode, dummyFilePosition);

// Make sure every class directly or indirectly inherits from MOAILuaObject
Expand Down Expand Up @@ -138,14 +138,14 @@ public IEnumerable<MoaiType> DocumentedTypes {
}
}

private void ParseMoaiCodeFiles(DirectoryInfo moaiSourceDirectory, bool fullPathInMessages) {
private void ParseMoaiCodeFiles(DirectoryInfo moaiSourceDirectory, PathFormat messagePathFormat) {
IEnumerable<FileInfo> codeFiles = Directory
.EnumerateFiles(moaiSourceDirectory.FullName, "*.*", SearchOption.AllDirectories)
.Where(name => name.EndsWith(".cpp") || name.EndsWith(".h"))
.Select(name => new FileInfo(name));

foreach (var codeFile in codeFiles) {
FilePosition filePosition = new FilePosition(codeFile, moaiSourceDirectory, fullPathInMessages);
FilePosition filePosition = new FilePosition(codeFile, moaiSourceDirectory, messagePathFormat);
ParseMoaiCodeFile(codeFile, filePosition);
}
}
Expand Down
7 changes: 7 additions & 0 deletions MoaiUtils/CreateApiDescription/PathFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MoaiUtils.CreateApiDescription {
public enum PathFormat {
Absolute,
Relative,
URI
}
}
2 changes: 1 addition & 1 deletion MoaiUtils/CreateApiDescription/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static int Main(string[] args) {

// Parse Moai code
var parser = new MoaiCodeParser();
parser.Parse(new DirectoryInfo(configuration.InputDirectory), configuration.FullPathInMessages);
parser.Parse(new DirectoryInfo(configuration.InputDirectory), configuration.MessagePathFormat);

var methods = parser.DocumentedTypes
.SelectMany(type => type.Members.OfType<MoaiMethod>())
Expand Down

0 comments on commit 84ed8e4

Please sign in to comment.