-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added options to run AD to export layout to image (#365)
- Loading branch information
Showing
7 changed files
with
195 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Collections.Generic; | ||
using CommandLine; | ||
|
||
namespace AnnoDesigner | ||
{ | ||
[Verb("askAdmin")] | ||
public class AdminRestartArgs | ||
{ | ||
public const string Arguments = "askAdmin"; | ||
} | ||
|
||
[Verb("open")] | ||
public class OpenArgs | ||
{ | ||
[Value(0, HelpText = "Input AD file", Required = true)] | ||
public string Filename { get; set; } | ||
} | ||
|
||
[Verb("export")] | ||
public class ExportArgs | ||
{ | ||
[Value(0, HelpText = "Input AD file", Required = true)] | ||
public string Filename { get; set; } | ||
|
||
[Value(1, HelpText = "Exported png file", Required = true)] | ||
public string ExportedFilename { get; set; } | ||
|
||
[Option("border", Default = 1)] | ||
public int Border { get; set; } | ||
|
||
[Option("gridSize", Default = 20)] | ||
public int GridSize { get; set; } | ||
|
||
[Option("renderGrid", Default = true)] | ||
public bool RenderGrid { get; set; } | ||
|
||
[Option("renderHarborBlockedArea")] | ||
public bool RenderHarborBlockedArea { get; set; } | ||
|
||
[Option("renderIcon", Default = true)] | ||
public bool RenderIcon { get; set; } | ||
|
||
[Option("renderInfluences")] | ||
public bool RenderInfluences { get; set; } | ||
|
||
[Option("renderLabel", Default = true)] | ||
public bool RenderLabel { get; set; } | ||
|
||
[Option("renderPanorama")] | ||
public bool RenderPanorama { get; set; } | ||
|
||
[Option("renderStatistics")] | ||
public bool RenderStatistics { get; set; } | ||
|
||
[Option("renderTrueInfluenceRange")] | ||
public bool RenderTrueInfluenceRange { get; set; } | ||
|
||
[Option("renderVersion")] | ||
public bool RenderVersion { get; set; } | ||
} | ||
|
||
public static class ArgumentParser | ||
{ | ||
public static object Parse(IEnumerable<string> arguments) | ||
{ | ||
return Parser.Default.ParseArguments<AdminRestartArgs, OpenArgs, ExportArgs>(arguments).MapResult(x => x, _ => null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace AnnoDesigner.Tests | ||
{ | ||
public class ArgumentParserTests | ||
{ | ||
[Fact] | ||
public void Parse_EmptyArguments_ShouldReturnNull() | ||
{ | ||
// Arrange/Act | ||
var parsedArguments = ArgumentParser.Parse(Enumerable.Empty<string>()); | ||
|
||
// Assert | ||
Assert.Null(parsedArguments); | ||
} | ||
|
||
[Fact] | ||
public void Parse_UnknownVerb_ShouldReturnNull() | ||
{ | ||
// Arrange/Act | ||
var parsedArguments = ArgumentParser.Parse(new[] { "unknown" }); | ||
|
||
// Assert | ||
Assert.Null(parsedArguments); | ||
} | ||
|
||
[Fact] | ||
public void Parse_AskAdminVerb_ShouldReturnCorrectType() | ||
{ | ||
// Arrange/Act | ||
var parsedArguments = ArgumentParser.Parse(new[] { "askAdmin" }); | ||
|
||
// Assert | ||
Assert.IsType<AdminRestartArgs>(parsedArguments); | ||
} | ||
|
||
[Fact] | ||
public void Parse_OpenVerb_ShouldReturnNullIfFilenameNotSpecified() | ||
{ | ||
// Arrange/Act | ||
var parsedArguments = ArgumentParser.Parse(new[] { "open" }); | ||
|
||
// Assert | ||
Assert.Null(parsedArguments); | ||
} | ||
|
||
[Fact] | ||
public void Parse_OpenVerb_ShouldReturnParsedFilename() | ||
{ | ||
// Arrange/Act | ||
var parsedArguments = ArgumentParser.Parse(new[] { "open", "filename" }); | ||
|
||
// Assert | ||
Assert.IsType<OpenArgs>(parsedArguments); | ||
Assert.Equal("filename", (parsedArguments as OpenArgs).Filename); | ||
} | ||
|
||
[Fact] | ||
public void Parse_ExportVerb_ShouldReturnNullIfLayoutFileNotSpecified() | ||
{ | ||
// Arrange/Act | ||
var parsedArguments = ArgumentParser.Parse(new[] { "export" }); | ||
|
||
// Assert | ||
Assert.Null(parsedArguments); | ||
} | ||
|
||
[Fact] | ||
public void Parse_ExportVerb_ShouldReturnNullIfOutputFileNotSpecified() | ||
{ | ||
// Arrange/Act | ||
var parsedArguments = ArgumentParser.Parse(new[] { "export", "filename" }); | ||
|
||
// Assert | ||
Assert.Null(parsedArguments); | ||
} | ||
|
||
[Fact] | ||
public void Parse_ExportVerb_ShouldReturnParsedValues() | ||
{ | ||
// Arrange/Act | ||
var parsedArguments = ArgumentParser.Parse(new[] { "export", "filename", "output", "--border", "5" }); | ||
|
||
// Assert | ||
Assert.IsType<ExportArgs>(parsedArguments); | ||
Assert.Equal("filename", (parsedArguments as ExportArgs).Filename); | ||
Assert.Equal("output", (parsedArguments as ExportArgs).ExportedFilename); | ||
Assert.Equal(5, (parsedArguments as ExportArgs).Border); | ||
} | ||
} | ||
} |