diff --git a/EntityDb.MongoDb.Provisioner/Commands/CreateCollectionsDirect.cs b/EntityDb.MongoDb.Provisioner/Commands/CreateCollectionsDirect.cs new file mode 100644 index 00000000..c7e8deea --- /dev/null +++ b/EntityDb.MongoDb.Provisioner/Commands/CreateCollectionsDirect.cs @@ -0,0 +1,36 @@ +using EntityDb.MongoDb.Extensions; +using MongoDB.Driver; +using System.CommandLine; +using System.CommandLine.Invocation; +using System.Threading.Tasks; + +namespace EntityDb.MongoDb.Provisioner.Commands +{ + public class CreateCollectionsDirect : CommandBase + { + public static void AddTo(RootCommand rootCommand) + { + var createCollectionsDirect = new Command("create-collections-direct"); + + AddEntityNameArgumentTo(createCollectionsDirect); + + var connectionStringArgument = new Argument("connection-string", "The connection string to the mongodb instance."); + + createCollectionsDirect.AddArgument(connectionStringArgument); + + createCollectionsDirect.Handler = CommandHandler.Create(async (string entityName, string connectionString) => + { + await Execute(entityName, connectionString); + }); + + rootCommand.AddCommand(createCollectionsDirect); + } + + public static async Task Execute(string entityName, string connectionString) + { + var mongoClient = new MongoClient(connectionString); + + await mongoClient.ProvisionCollections(entityName); + } + } +} diff --git a/EntityDb.MongoDb.Provisioner/Program.cs b/EntityDb.MongoDb.Provisioner/Program.cs index 2cdfca2c..c25b033f 100644 --- a/EntityDb.MongoDb.Provisioner/Program.cs +++ b/EntityDb.MongoDb.Provisioner/Program.cs @@ -1,33 +1,34 @@ -using EntityDb.MongoDb.Provisioner.Commands; -using System; -using System.CommandLine; -using System.CommandLine.Parsing; -using System.Threading.Tasks; - -namespace EntityDb.MongoDb.Provisioner -{ - public class Program - { - public static Task Main(string[] args) - { -#if DEBUG - if (args.Length == 0) - { - Console.Write("Please enter args: "); - - var input = Console.ReadLine() ?? string.Empty; - - args = input.Split(' '); - } -#endif - - var rootCommand = new RootCommand(); - - CreateRole.AddTo(rootCommand); - CreateUser.AddTo(rootCommand); - CreateCollections.AddTo(rootCommand); - - return rootCommand.InvokeAsync(args); - } - } -} +using EntityDb.MongoDb.Provisioner.Commands; +using System; +using System.CommandLine; +using System.CommandLine.Parsing; +using System.Threading.Tasks; + +namespace EntityDb.MongoDb.Provisioner +{ + public class Program + { + public static Task Main(string[] args) + { +#if DEBUG + if (args.Length == 0) + { + Console.Write("Please enter args: "); + + var input = Console.ReadLine() ?? string.Empty; + + args = input.Split(' '); + } +#endif + + var rootCommand = new RootCommand(); + + CreateRole.AddTo(rootCommand); + CreateUser.AddTo(rootCommand); + CreateCollections.AddTo(rootCommand); + CreateCollectionsDirect.AddTo(rootCommand); + + return rootCommand.InvokeAsync(args); + } + } +}