Skip to content

Commit

Permalink
Merge pull request abpframework#11335 from abpframework/issue/10709
Browse files Browse the repository at this point in the history
CLI: Throw exception when a parameter is invalid
  • Loading branch information
ebicoglu authored Jan 18, 2022
2 parents efbbc7d + 983ed6b commit d27b50e
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,23 @@ protected static string GetConnectionString(CommandLineArgs commandLineArgs)
protected virtual DatabaseProvider GetDatabaseProvider(CommandLineArgs commandLineArgs)
{
var optionValue = commandLineArgs.Options.GetOrNull(Options.DatabaseProvider.Short, Options.DatabaseProvider.Long);
switch (optionValue)

if (optionValue == null)
{
case "ef":
return DatabaseProvider.EntityFrameworkCore;
case "mongodb":
return DatabaseProvider.MongoDb;
default:
return DatabaseProvider.NotSpecified;
return DatabaseProvider.NotSpecified;
}

if (optionValue.Equals("ef", StringComparison.InvariantCultureIgnoreCase) || optionValue.Equals("entityframeworkcore", StringComparison.InvariantCultureIgnoreCase))
{
return DatabaseProvider.EntityFrameworkCore;
}

if (optionValue.Equals("mongo", StringComparison.InvariantCultureIgnoreCase) || optionValue.Equals("mongodb", StringComparison.InvariantCultureIgnoreCase))
{
return DatabaseProvider.MongoDb;
}

throw new CliUsageException("The option you provided for Database Provider is invalid!");
}

protected virtual void RunGraphBuildForMicroserviceServiceTemplate(ProjectBuildArgs projectArgs)
Expand Down Expand Up @@ -322,7 +330,7 @@ protected virtual DatabaseManagementSystem GetDatabaseManagementSystem(CommandLi
case "oracle":
return DatabaseManagementSystem.Oracle;
default:
return DatabaseManagementSystem.NotSpecified;
throw new CliUsageException("The option you provided for Database Management System is invalid!");
}
}

Expand All @@ -332,12 +340,13 @@ protected virtual MobileApp GetMobilePreference(CommandLineArgs commandLineArgs)

switch (optionValue)
{
case null:
case "none":
return MobileApp.None;
case "react-native":
return MobileApp.ReactNative;
default:
return MobileApp.None;
throw new CliUsageException("The option you provided for Mobile App is invalid!");
}
}

Expand All @@ -349,8 +358,11 @@ protected virtual UiFramework GetUiFramework(CommandLineArgs commandLineArgs)
}

var optionValue = commandLineArgs.Options.GetOrNull(Options.UiFramework.Short, Options.UiFramework.Long);

switch (optionValue)
{
case null:
return UiFramework.NotSpecified;
case "none":
return UiFramework.None;
case "mvc":
Expand All @@ -362,7 +374,7 @@ protected virtual UiFramework GetUiFramework(CommandLineArgs commandLineArgs)
case "blazor-server":
return UiFramework.BlazorServer;
default:
return UiFramework.NotSpecified;
throw new CliUsageException("The option you provided for UI Framework is invalid!");
}
}

Expand Down

0 comments on commit d27b50e

Please sign in to comment.