From 69198d11a8208b7810a5ce1a91b7d8d3d0bb900e Mon Sep 17 00:00:00 2001 From: Tran Minh Luan Date: Thu, 8 Aug 2024 15:11:16 +0700 Subject: [PATCH] all: remove dependencies (#28) --- .../Atlas.Provider.Core.csproj | 3 - src/Atlas.Provider.Core/Options.cs | 74 +++++++++++++++++++ src/Atlas.Provider.Core/Program.cs | 29 +++----- 3 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 src/Atlas.Provider.Core/Options.cs diff --git a/src/Atlas.Provider.Core/Atlas.Provider.Core.csproj b/src/Atlas.Provider.Core/Atlas.Provider.Core.csproj index 2bed170..7e3fc94 100644 --- a/src/Atlas.Provider.Core/Atlas.Provider.Core.csproj +++ b/src/Atlas.Provider.Core/Atlas.Provider.Core.csproj @@ -15,7 +15,4 @@ false False - - - \ No newline at end of file diff --git a/src/Atlas.Provider.Core/Options.cs b/src/Atlas.Provider.Core/Options.cs new file mode 100644 index 0000000..06a8b3f --- /dev/null +++ b/src/Atlas.Provider.Core/Options.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; + +namespace Atlas.Provider.Core +{ + public class Options + { + public string Assembly { get; set; } = string.Empty; + public string Project { get; set; } = string.Empty; + public string StartupAssembly { get; set; } = string.Empty; + public string StartupProject { get; set; } = string.Empty; + public string ProjectDir { get; set; } = string.Empty; + public string RootNamespace { get; set; } = string.Empty; + public string Language { get; set; } = string.Empty; + public string Framework { get; set; } = string.Empty; + public string WorkingDir { get; set; } = string.Empty; + public bool Nullable { get; set; } = true; + public List? PositionalArgs { get; set; } + + public Options(string[] args) + { + for (int i = 0; i < args.Length; i++) + { + switch (args[i]) + { + case "--assembly": + if (i + 1 < args.Length) Assembly = args[++i]; + break; + case "--project": + if (i + 1 < args.Length) Project = args[++i]; + break; + case "--startup-assembly": + if (i + 1 < args.Length) StartupAssembly = args[++i]; + break; + case "--startup-project": + if (i + 1 < args.Length) StartupProject = args[++i]; + break; + case "--project-dir": + if (i + 1 < args.Length) ProjectDir = args[++i]; + break; + case "--root-namespace": + if (i + 1 < args.Length) RootNamespace = args[++i]; + break; + case "--language": + if (i + 1 < args.Length) Language = args[++i]; + break; + case "--framework": + if (i + 1 < args.Length) Framework = args[++i]; + break; + case "--working-dir": + if (i + 1 < args.Length) WorkingDir = args[++i]; + break; + default: + if (PositionalArgs == null) + { + PositionalArgs = new List(); + } + PositionalArgs.Add(args[i]); + break; + } + } + + if (string.IsNullOrEmpty(Assembly)) throw new ArgumentException("--assembly option requires a value."); + if (string.IsNullOrEmpty(Project)) throw new ArgumentException("--project option requires a value."); + if (string.IsNullOrEmpty(StartupAssembly)) throw new ArgumentException("--startupAssembly option requires a value."); + if (string.IsNullOrEmpty(StartupProject)) throw new ArgumentException("--startupProject option requires a value."); + if (string.IsNullOrEmpty(ProjectDir)) throw new ArgumentException("--projectDir option requires a value."); + if (string.IsNullOrEmpty(RootNamespace)) throw new ArgumentException("--rootNamespace option requires a value."); + if (string.IsNullOrEmpty(Language)) throw new ArgumentException("--language option requires a value."); + if (string.IsNullOrEmpty(Framework)) throw new ArgumentException("--framework option requires a value."); + if (string.IsNullOrEmpty(WorkingDir)) throw new ArgumentException("--workingDir option requires a value."); + } + } +} \ No newline at end of file diff --git a/src/Atlas.Provider.Core/Program.cs b/src/Atlas.Provider.Core/Program.cs index 789ba6a..0ad42a7 100644 --- a/src/Atlas.Provider.Core/Program.cs +++ b/src/Atlas.Provider.Core/Program.cs @@ -6,34 +6,23 @@ namespace Atlas.Provider.Core { static class Program { - static int Main( - string assembly, - string project, - string startupAssembly, - string startupProject, - string projectDir, - string rootNamespace, - string language, - string framework, - string workingDir, - bool nullable = true, - string[]? args = null - ) + static int Main(string[] args) { try { + var options = new Options(args); // prevent any output from being written to the console, including warn, info, error etc messages from EF Core var originalOut = Console.Out; Console.SetOut(TextWriter.Null); using var executor = new EFDesign( - assembly, - startupAssembly, - projectDir, + options.Assembly, + options.StartupAssembly, + options.ProjectDir, null, - rootNamespace, - language, - nullable, - args + options.RootNamespace, + options.Language, + options.Nullable, + options.PositionalArgs?.ToArray() ); var types = executor.GetContextTypes(); foreach (var type in types)