Skip to content

Commit

Permalink
Rewrite CommandLineArgumentsProvider to be usable without subclassing
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed May 30, 2021
1 parent 9fbbe8e commit 9857951
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions XmlSchemaClassGenerator/CommandLineArgumentsProvider.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;

namespace XmlSchemaClassGenerator
{
public class CommandLineArgumentsProvider
{
public virtual string CommandLineArguments
public CommandLineArgumentsProvider(string commandLineArguments)
{
get
{
var args = Environment.GetCommandLineArgs();
return string.Join(" ", args.Take(1).Select(Path.GetFileNameWithoutExtension).Concat(args.Skip(1)).Select(Extensions.QuoteIfNeeded));
}
CommandLineArguments = commandLineArguments ?? throw new ArgumentNullException(nameof(commandLineArguments));
}

public string CommandLineArguments { get; }

public static CommandLineArgumentsProvider CreateFromEnvironment()
{
var args = Environment.GetCommandLineArgs();
var commandLineArguments = string.Join(" ", args.Take(1).Select(Path.GetFileNameWithoutExtension).Concat(args.Skip(1)).Select(Extensions.QuoteIfNeeded));
return new CommandLineArgumentsProvider(commandLineArguments);
}
}
}
2 changes: 1 addition & 1 deletion XmlSchemaClassGenerator/GeneratorConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public GeneratorConfiguration()
NamingProvider = new NamingProvider(NamingScheme);
Version = VersionProvider.CreateFromAssembly();
EnableUpaCheck = true;
CommandLineArgumentsProvider = new CommandLineArgumentsProvider();
CommandLineArgumentsProvider = CommandLineArgumentsProvider.CreateFromEnvironment();
}

/// <summary>
Expand Down

0 comments on commit 9857951

Please sign in to comment.