Skip to content

Commit

Permalink
Allow output type and startup name override for gh actoin
Browse files Browse the repository at this point in the history
  • Loading branch information
maisiesadler committed May 6, 2021
1 parent 8f03e79 commit 8da23a5
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ The GitHub action is defined [here](./acton.yml) and uses the [Dockerfile](./Do
| Skip types | `SKIP_TYPES` | `-s` `--skip-types` | Types to skip, multiple values can be used as a csv input | No |
| Assembly Config Location | `ASSEMBLY_CONFIG_LOCATION` | `--assembly-config` | The location of the configuration file required to build IConfiguration for Startup | No |
| Interface Resolver | `INTERFACE_RESOLVER` | `-i` `--interface-resolver` | Method for resolving interfaces, Allowed Values: None, Startup. Default: Startup. | No |
| Startup Name | `STARTUP_NAME` | `--startup-name` | Startup Type Name or FullName. Default: Startup. | No |
| Output Format | `OUTPUT_FORMAT` | `--output-format` | Format to print out the result. Allowed values: debug, yumlmd, yuml. Default: yuml. | No |
| Startup Name | `STARTUP_NAME` | `--startup-name` | Startup Type Name or FullName. Default: `Startup`. | No |
| Output Format | `OUTPUT_FORMAT` | `--output-format` | Format to print out the result. Allowed values: `debug`, `yumlmd`, `yuml`. Default: `yuml`. | No |
| Application Config Location | `APPLICATION_CONFIG_LOCATION` | `-c` `--config` | The location of application config file | No |

### Application config
Expand Down
6 changes: 5 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
dotnet publish ./src/DepTree.Console/DepTree.Console.csproj -c Release -o out --no-self-contained

ASSEMBLY_LOCATION=/Users/maisiesadler/repos/endpoints/src/Endpoints.Api/bin/Release/net5.0/osx.10.12-x64/Endpoints.Api.dll
ROOT_TYPES=Pokedex.Controllers.PokemonController
ROOT_TYPES=Endpoints.Api.Domain.MyModelRetriever
INTERFACE_RESOLVER=None
OUTPUT_FORMAT=debug

ASSEMBLY_LOCATION=$ASSEMBLY_LOCATION \
APPLICATION_CONFIG_LOCATION=$APPLICATION_CONFIG_LOCATION \
ROOT_TYPES=$ROOT_TYPES \
SKIP_TYPES=$SKIP_TYPES \
ASSEMBLY_CONFIG_LOCATION=$ASSEMBLY_CONFIG_LOCATION \
INTERFACE_RESOLVER=$INTERFACE_RESOLVER \
OUTPUT_FORMAT=$OUTPUT_FORMAT \
STARTUP_NAME=$STARTUP_NAME \
dotnet out/DepTree.Console.dll
2 changes: 2 additions & 0 deletions runindocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ result=$(ASSEMBLY_LOCATION=$ASSEMBLY_LOCATION \
SKIP_TYPES=$SKIP_TYPES \
ASSEMBLY_CONFIG_LOCATION=$ASSEMBLY_CONFIG_LOCATION \
INTERFACE_RESOLVER=$INTERFACE_RESOLVER \
OUTPUT_FORMAT=$OUTPUT_FORMAT \
STARTUP_NAME=$STARTUP_NAME \
dotnet /DepTree.Console.dll)

r=$?
Expand Down
2 changes: 1 addition & 1 deletion src/DepTree.Console.Tests/ArgConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void CanSpecifyOutputFormat()
var (config, ok) = ApplicationConfiguration.Build(new TestEnvironmentVariableProvider(), args);

Assert.NotNull(config);
Assert.Equal("yuml", config.OutputFormat);
Assert.Equal(OutputFormatType.Yuml, config.OutputFormat);
}
}
}
13 changes: 9 additions & 4 deletions src/DepTree.Console.Tests/EnvConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,23 @@ public void CanSpecifyStartupNameOverride()
Assert.Equal("TestStartup", config.StartupName);
}

[Fact]
public void CanSpecifyOutputFormat()
[Theory]
[InlineData("yuml", OutputFormatType.Yuml)]
[InlineData("yumlmd", OutputFormatType.YumlMd)]
[InlineData("debug", OutputFormatType.Debug)]
[InlineData("beans", OutputFormatType.YumlMd)]
[InlineData("", OutputFormatType.YumlMd)]
public void CanSpecifyOutputFormat(string format, OutputFormatType expectedType)
{
var provider = new TestEnvironmentVariableProvider
{
{ "ASSEMBLY_LOCATION", "assembly-location" },
{ "OUTPUT_FORMAT", "yuml" }
{ "OUTPUT_FORMAT", format }
};
var (config, ok) = ApplicationConfiguration.Build(provider, new string[] { });

Assert.NotNull(config);
Assert.Equal("yuml", config.OutputFormat);
Assert.Equal(expectedType, config.OutputFormat);
}
}
}
22 changes: 16 additions & 6 deletions src/DepTree.Console/Configuration/ApplicationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private ApplicationConfiguration() { }
public List<string> Errors { get; private set; } = new List<string>();
public InterfaceResolverType InterfaceResolverType { get; private set; } = Resolvers.InterfaceResolverType.Startup;
public string StartupName { get; private set; } = "Startup";
public string OutputFormat { get; private set; } = "yumlmd";
public OutputFormatType OutputFormat { get; private set; } = OutputFormatType.YumlMd;
public bool IsValid => Errors.Count == 0;

public static (ApplicationConfiguration, bool) Build(IEnvironmentVariableProvider environmentVariableProvider, string[] args)
Expand Down Expand Up @@ -56,7 +56,7 @@ private void ReadEnvironmentVariables(IEnvironmentVariableProvider environmentVa
_configLocation = environmentVariableProvider.GetEnvironmentVariable("APPLICATION_CONFIG_LOCATION");
StartupName = environmentVariableProvider.GetEnvironmentVariable("STARTUP_NAME");
TrySetInterfaceResolver(environmentVariableProvider.GetEnvironmentVariable("INTERFACE_RESOLVER"));
OutputFormat = environmentVariableProvider.GetEnvironmentVariable("OUTPUT_FORMAT");
TrySetOutputFormat(environmentVariableProvider.GetEnvironmentVariable("OUTPUT_FORMAT"));

var rootTypes = environmentVariableProvider.GetEnvironmentVariable("ROOT_TYPES");
if (!string.IsNullOrWhiteSpace(rootTypes))
Expand Down Expand Up @@ -88,7 +88,7 @@ private void TryReadArgs(string[] args)
StartupName = inputs.StartupName;

if (!string.IsNullOrWhiteSpace(inputs.OutputFormat))
OutputFormat = inputs.OutputFormat;
TrySetOutputFormat(inputs.OutputFormat);

if (!string.IsNullOrWhiteSpace(inputs.RootTypes))
{
Expand Down Expand Up @@ -144,12 +144,22 @@ private void TryBuildAssemblyConfiguration()
}
}

private void TrySetInterfaceResolver(string interfaceResolver)
private void TrySetInterfaceResolver(string value)
{
if (interfaceResolver == "None")
if (value == "None")
InterfaceResolverType = Resolvers.InterfaceResolverType.None;
else if (interfaceResolver == "Startup")
else if (value == "Startup")
InterfaceResolverType = Resolvers.InterfaceResolverType.Startup;
}

private void TrySetOutputFormat(string value)
{
if (value == "yumlmd")
OutputFormat = OutputFormatType.YumlMd;
else if (value == "yuml")
OutputFormat = OutputFormatType.Yuml;
else if (value == "debug")
OutputFormat = OutputFormatType.Debug;
}
}
}
9 changes: 9 additions & 0 deletions src/DepTree.Console/Configuration/OutputFormatType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DepTree.Console.Configuration
{
public enum OutputFormatType
{
Yuml,
YumlMd,
Debug,
}
}
10 changes: 7 additions & 3 deletions src/DepTree.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,28 @@ static int Main(string[] args)
nodes.Add(node);
}

if (applicationConfig.OutputFormat == "yumlmd")
if (applicationConfig.OutputFormat == OutputFormatType.YumlMd)
{
var diagram = yUMLmd.Create(nodes);
System.Console.WriteLine(diagram);
}
else if (applicationConfig.OutputFormat == "yuml")
else if (applicationConfig.OutputFormat == OutputFormatType.Yuml)
{
var diagram = yUML.Create(nodes);
System.Console.WriteLine(diagram);
}
else
else if (applicationConfig.OutputFormat == OutputFormatType.Debug)
{
System.Console.WriteLine($"Got {nodes?.Count} nodes");
foreach (var node in nodes)
{
Print(node);
}
}
else
{
System.Console.WriteLine($"OutputFormat '{applicationConfig.OutputFormat}' unknown");
}

return 0;
}
Expand Down

0 comments on commit 8da23a5

Please sign in to comment.