Skip to content

Commit

Permalink
Adding --excludeFiles for identity scaffolding (dotnet#1324)
Browse files Browse the repository at this point in the history
* added excludeFiles flag for identity

* minor fix and removing unused property

* description fixes
  • Loading branch information
deepchoudhery authored Apr 27, 2020
1 parent 6946271 commit 84bf7c3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class IdentityGeneratorCommandLineModel
[Option(Name ="bootstrapVersion", ShortName = "b", Description = "Specify the bootstrap version. Valid values: '3', '4'. Default is 4.")]
public string BootstrapVersion { get; set; }

[Option(Name ="excludeFiles", ShortName="exf", Description = "Use this option to overwrite all but list of semicolon separated files. Use the --listFiles option to see the available options.")]
public string ExcludeFiles { get; set; }

public bool IsGenerateCustomUser
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class IdentityGeneratorTemplateModel
public bool UseSQLite { get; set; }
public bool IsUsingExistingDbContext { get; set; }
public bool IsGenerateCustomUser { get; set; }
public bool IsGeneratingIndividualFiles { get; set; }
public IdentityGeneratorFile[] FilesToGenerate { get; set; }
public bool UseDefaultUI { get; set; }
public bool GenerateLayout { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public IdentityGeneratorTemplateModelBuilder(
}

internal bool IsFilesSpecified => !string.IsNullOrEmpty(_commandlineModel.Files);
internal bool IsExcludeSpecificed => !string.IsNullOrEmpty(_commandlineModel.ExcludeFiles);
internal bool IsDbContextSpecified => !string.IsNullOrEmpty(_commandlineModel.DbContext);
internal bool IsUsingExistingDbContext { get; set; }

Expand Down Expand Up @@ -197,7 +198,6 @@ public async Task<IdentityGeneratorTemplateModel> ValidateAndBuild()
IsUsingExistingDbContext = IsUsingExistingDbContext,
Namespace = RootNamespace,
IsGenerateCustomUser = IsGenerateCustomUser,
IsGeneratingIndividualFiles = IsFilesSpecified,
UseDefaultUI = _commandlineModel.UseDefaultUI,
GenerateLayout = !hasExistingLayout,
Layout = layout,
Expand All @@ -210,17 +210,54 @@ public async Task<IdentityGeneratorTemplateModel> ValidateAndBuild()

templateModel.ContentVersion = DetermineContentVersion(templateModel);

ValidateIndividualFileOptions();
if (!string.IsNullOrEmpty(_commandlineModel.Files))
{
NamedFiles = _commandlineModel.Files.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
}
else if(!string.IsNullOrEmpty(_commandlineModel.ExcludeFiles))
{
string contentVersion;
if (templateModel is IdentityGeneratorTemplateModel2 templateModel2)
{
contentVersion = templateModel2.ContentVersion;
}
else
{
contentVersion = IdentityGenerator.ContentVersionDefault;
}
IEnumerable<string> excludedFiles = _commandlineModel.ExcludeFiles.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToList();
IEnumerable<string> allFiles = IdentityGeneratorFilesConfig.GetFilesToList(contentVersion);
//validate excluded files
var errors = new List<string>();
var invalidFiles = excludedFiles.Where(f => !allFiles.Contains(f));
if (invalidFiles.Any())
{
errors.Add(MessageStrings.InvalidFilesListMessage);
errors.AddRange(invalidFiles);
}

if (errors.Any())
{
throw new InvalidOperationException(string.Join(Environment.NewLine, errors));
}

//get files to overwrite
NamedFiles = allFiles.Except(excludedFiles);
}

templateModel.FilesToGenerate = DetermineFilesToGenerate(templateModel);

if (IsFilesSpecified)
{
ValidateFilesOption(templateModel);
}

if (IsExcludeSpecificed)
{
ValidateFilesOption(templateModel);
}

return templateModel;
}

Expand Down Expand Up @@ -407,6 +444,14 @@ private bool HasExistingNonEmptyWwwRootDirectory
}
}

private void ValidateIndividualFileOptions()
{
//Both options should not be selected. Users should either scaffold a particular set of files OR exclude a particular set of files.
if(IsFilesSpecified && IsExcludeSpecificed)
{
throw new InvalidOperationException(string.Format(MessageStrings.InvalidOptionCombination,"--files", "--excludeFiles"));
}
}
private void ValidateDefaultUIOption()
{
var errorStrings = new List<string>();
Expand All @@ -416,6 +461,11 @@ private void ValidateDefaultUIOption()
errorStrings.Add(string.Format(MessageStrings.InvalidOptionCombination,"--files", "--useDefaultUI"));
}

if(IsExcludeSpecificed)
{
errorStrings.Add(string.Format(MessageStrings.InvalidOptionCombination,"--excludeFiles", "--useDefaultUI"));
}

if (IsUsingExistingDbContext)
{
errorStrings.Add(MessageStrings.ExistingDbContextCannotBeUsedForDefaultUI);
Expand Down

0 comments on commit 84bf7c3

Please sign in to comment.