src/Commands/Cosmos/BaseDatabaseCommand.cs (33 lines of code) (raw):

// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.CommandLine; using System.CommandLine.Parsing; using System.Diagnostics.CodeAnalysis; using AzureMcp.Arguments.Cosmos; using AzureMcp.Models.Argument; namespace AzureMcp.Commands.Cosmos; public abstract class BaseDatabaseCommand< [DynamicallyAccessedMembers(TrimAnnotations.CommandAnnotations)] TArgs> : BaseCosmosCommand<TArgs> where TArgs : BaseDatabaseArguments, new() { protected readonly Option<string> _databaseOption = ArgumentDefinitions.Cosmos.Database.ToOption(); protected override void RegisterOptions(Command command) { base.RegisterOptions(command); command.AddOption(_databaseOption); } protected override void RegisterArguments() { base.RegisterArguments(); AddArgument(CreateDatabaseArgument()); } protected override TArgs BindArguments(ParseResult parseResult) { var args = base.BindArguments(parseResult); args.Database = parseResult.GetValueForOption(_databaseOption); return args; } protected ArgumentBuilder<TArgs> CreateDatabaseArgument() => ArgumentBuilder<TArgs> .Create(ArgumentDefinitions.Cosmos.Database.Name, ArgumentDefinitions.Cosmos.Database.Description) .WithValueAccessor(args => args.Database ?? string.Empty) .WithIsRequired(ArgumentDefinitions.Cosmos.Database.Required); }