Skip to content

Commit

Permalink
Merge branch 'better-default-value-handling'
Browse files Browse the repository at this point in the history
  • Loading branch information
petrsvihlik committed Feb 2, 2018
2 parents 73cdb5d + 8c1ede6 commit b04bd0b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/CloudModelGenerator/ClassCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class ClassCodeGenerator
public ClassCodeGenerator(ClassDefinition classDefinition, string classFilename, string @namespace = DEFAULT_NAMESPACE, bool customPartial = false)
{
ClassDefinition = classDefinition ?? throw new ArgumentNullException(nameof(classDefinition));
ClassFilename = classFilename ?? ClassDefinition.ClassName;
ClassFilename = string.IsNullOrEmpty(classFilename) ? ClassDefinition.ClassName : classFilename;
CustomPartial = customPartial;
Namespace = @namespace ?? DEFAULT_NAMESPACE;
Namespace = string.IsNullOrEmpty(@namespace) ? DEFAULT_NAMESPACE : @namespace;
OverwriteExisting = !CustomPartial;
}

Expand Down
2 changes: 1 addition & 1 deletion src/CloudModelGenerator/CloudModelGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
<PackageReference Include="System.CommandLine" Version="0.1.0-*" />
<PackageReference Include="System.CommandLine" Version="0.1.0-preview2-180131-1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
public class CodeGeneratorOptions
{
public static string DefaultOutputDir = ".";
public static bool DefaultGeneratePartials = false;
public static bool DefaultWithTypeProvider = true;
public static bool DefaultStructuredModel = false;
Expand All @@ -21,7 +20,7 @@ public class CodeGeneratorOptions
/// <summary>
/// Output directory for the generated files
/// </summary>
public string OutputDir { get; set; } = DefaultOutputDir;
public string OutputDir { get; set; }

/// <summary>
/// Optionally add suffix to the generated files
Expand Down
15 changes: 9 additions & 6 deletions src/CloudModelGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ static int Main(string[] args)

static ArgumentSyntax Parse(string[] args)
{
string projectIdDefaultValue = null;
string namespaceDefaultValue = null;
string outputDirDefaultValue = null;
string fileNameSuffixDefaultValue = null;

var result = ArgumentSyntax.Parse(args, syntax =>
{

syntax.ErrorOnUnexpectedArguments = false;
string nullStr = null;
syntax.DefineOption("p|projectid", ref nullStr, "Kentico Cloud Project ID.");
syntax.DefineOption("n|namespace", ref nullStr, "-n|--namespace");
syntax.DefineOption("o|outputdir", ref CodeGeneratorOptions.DefaultOutputDir, "Output directory for the generated files.");
syntax.DefineOption("f|filenamesuffix", ref nullStr, "Optionally add a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs).");
syntax.DefineOption("p|projectid", ref projectIdDefaultValue, "Kentico Cloud Project ID.");
syntax.DefineOption("n|namespace", ref namespaceDefaultValue, "-n|--namespace");
syntax.DefineOption("o|outputdir", ref outputDirDefaultValue, "Output directory for the generated files.");
syntax.DefineOption("f|filenamesuffix", ref fileNameSuffixDefaultValue, "Optionally add a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs).");
syntax.DefineOption("g|generatepartials", ref CodeGeneratorOptions.DefaultGeneratePartials, "Generate partial classes for customization (if this option is set filename suffix will default to Generated).");
syntax.DefineOption("t|withtypeprovider", ref CodeGeneratorOptions.DefaultWithTypeProvider, "Indicates whether the CustomTypeProvider class should be generated.");
syntax.DefineOption("s|structuredmodel", ref CodeGeneratorOptions.DefaultStructuredModel, "Indicates whether the classes should be generated with types that represent structured data model.");
Expand Down
2 changes: 1 addition & 1 deletion src/CloudModelGenerator/appSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Namespace": null,

// Output directory for the generated files
"OutputDir": null,
"OutputDir": "./output",

// Optionally add suffix to the generated files
"FileNameSuffix": null,
Expand Down

0 comments on commit b04bd0b

Please sign in to comment.