Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

6 changes: 6 additions & 0 deletions src/Cli/dotnet/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ protected virtual void ShowHelpOrErrorIfAppropriate(ParseResult parseResult)

public abstract int Execute();
}

public abstract class CommandBase<TDefinition>(ParseResult parseResult) : CommandBase(parseResult)
where TDefinition : Command
{
protected TDefinition Definition { get; } = (TDefinition)parseResult.CommandResult.Command;
}
28 changes: 14 additions & 14 deletions src/Cli/dotnet/Commands/Hidden/Add/AddCommandDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@

namespace Microsoft.DotNet.Cli.Commands.Hidden.Add;

internal static class AddCommandDefinition
internal sealed class AddCommandDefinition : Command
{
public const string Name = "add";
public new const string Name = "add";
private const string Link = "https://aka.ms/dotnet-add";

public static readonly string DocsLink = "https://aka.ms/dotnet-add";
public readonly AddPackageCommandDefinition PackageCommand = new();
public readonly AddReferenceCommandDefinition ReferenceCommand = new();

public static Command Create()
{
var command = new Command(Name, CliCommandStrings.NetAddCommand)
{
Hidden = true,
DocsLink = DocsLink
};
public readonly Argument<string> ProjectOrFileArgument = PackageCommandDefinition.CreateProjectOrFileArgument();

command.Arguments.Add(PackageCommandDefinition.ProjectOrFileArgument);
command.Subcommands.Add(AddPackageCommandDefinition.Create());
command.Subcommands.Add(AddReferenceCommandDefinition.Create());
public AddCommandDefinition()
: base(Name, CliCommandStrings.NetAddCommand)
{
Hidden = true;
this.DocsLink = Link;

return command;
Arguments.Add(ProjectOrFileArgument);
Subcommands.Add(PackageCommand);
Subcommands.Add(ReferenceCommand);
}
}
16 changes: 8 additions & 8 deletions src/Cli/dotnet/Commands/Hidden/Add/AddCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.Commands.Hidden.Add.Package;
using Microsoft.DotNet.Cli.Commands.Hidden.Add.Reference;
using System.CommandLine.Completions;
using Microsoft.DotNet.Cli.Commands.Package;
using Microsoft.DotNet.Cli.Commands.Package.Add;
using Microsoft.DotNet.Cli.Commands.Reference.Add;
using Microsoft.DotNet.Cli.Extensions;
Expand All @@ -12,19 +12,19 @@ namespace Microsoft.DotNet.Cli.Commands.Hidden.Add;

internal static class AddCommandParser
{
private static readonly Command Command = SetAction(AddCommandDefinition.Create());
private static readonly Command Command = SetActionAndCompletions(new AddCommandDefinition());

public static Command GetCommand()
{
return Command;
}

private static Command SetAction(Command command)
private static Command SetActionAndCompletions(AddCommandDefinition def)
{
command.SetAction((parseResult) => parseResult.HandleMissingCommand());
def.SetAction(parseResult => parseResult.HandleMissingCommand());

command.Subcommands.Single(c => c.Name == AddPackageCommandDefinition.Name).SetAction((parseResult) => new PackageAddCommand(parseResult).Execute());
command.Subcommands.Single(c => c.Name == AddReferenceCommandDefinition.Name).SetAction((parseResult) => new ReferenceAddCommand(parseResult).Execute());
return command;
PackageCommandParser.ConfigureAddCommand(def.PackageCommand);
def.ReferenceCommand.SetAction(parseResult => new ReferenceAddCommand(parseResult).Execute());
return def;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,16 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.Commands.Package;
using Microsoft.DotNet.Cli.Commands.Package.Add;

namespace Microsoft.DotNet.Cli.Commands.Hidden.Add.Package;

internal static class AddPackageCommandDefinition
internal sealed class AddPackageCommandDefinition() : PackageAddCommandDefinitionBase(Name)
{
public const string Name = "package";
public new const string Name = "package";

public static Command Create()
{
Command command = new(Name, CliCommandStrings.PackageAddAppFullName);
public AddCommandDefinition Parent => (AddCommandDefinition)Parents.Single();

command.Arguments.Add(PackageAddCommandDefinition.CmdPackageArgument);
command.Options.Add(PackageAddCommandDefinition.VersionOption);
command.Options.Add(PackageAddCommandDefinition.FrameworkOption);
command.Options.Add(PackageAddCommandDefinition.NoRestoreOption);
command.Options.Add(PackageAddCommandDefinition.SourceOption);
command.Options.Add(PackageAddCommandDefinition.PackageDirOption);
command.Options.Add(PackageAddCommandDefinition.InteractiveOption);
command.Options.Add(PackageAddCommandDefinition.PrereleaseOption);
command.Options.Add(PackageCommandDefinition.ProjectOption);
command.Options.Add(PackageCommandDefinition.FileOption);

return command;
}
public override Argument<string>? GetProjectOrFileArgument()
=> Parent.ProjectOrFileArgument;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Commands.Reference;
using Microsoft.DotNet.Cli.Commands.Reference.Add;

namespace Microsoft.DotNet.Cli.Commands.Hidden.Add.Reference;

internal static class AddReferenceCommandDefinition
internal sealed class AddReferenceCommandDefinition : ReferenceAddCommandDefinitionBase
{
public const string Name = "reference";
public new const string Name = "reference";

public static Command Create()
public readonly Option<string> ProjectOption = ReferenceCommandDefinition.CreateProjectOption();

public AddReferenceCommandDefinition()
: base(Name)
{
Command command = new(Name, CliCommandStrings.ReferenceAddAppFullName);
Options.Add(ProjectOption);
}

command.Arguments.Add(ReferenceAddCommandDefinition.ProjectPathArgument);
command.Options.Add(ReferenceAddCommandDefinition.FrameworkOption);
command.Options.Add(ReferenceAddCommandDefinition.InteractiveOption);
command.Options.Add(ReferenceCommandDefinition.ProjectOption);
public override string? GetFileOrDirectory(ParseResult parseResult)
=> parseResult.HasOption(ProjectOption)
? parseResult.GetValue(ProjectOption)
: parseResult.GetValue(Parent.ProjectOrFileArgument);

return command;
}
public AddCommandDefinition Parent => (AddCommandDefinition)Parents.Single();
}
32 changes: 16 additions & 16 deletions src/Cli/dotnet/Commands/Hidden/List/ListCommandDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@

namespace Microsoft.DotNet.Cli.Commands.Hidden.List;

internal static class ListCommandDefinition
internal sealed class ListCommandDefinition : Command
{
public static readonly string DocsLink = "https://aka.ms/dotnet-list";
private new const string Name = "list";
private const string Link = "https://aka.ms/dotnet-list";

public static readonly Argument<string> SlnOrProjectArgument = CreateSlnOrProjectArgument(CliStrings.SolutionOrProjectArgumentName, CliStrings.SolutionOrProjectArgumentDescription);

internal static Argument<string> CreateSlnOrProjectArgument(string name, string description)
public static Argument<string> CreateSlnOrProjectArgument(string name, string description)
=> new Argument<string>(name)
{
Description = description,
Arity = ArgumentArity.ZeroOrOne
}.DefaultToCurrentDirectory();

public static Command Create()
{
var command = new Command("list", CliCommandStrings.NetListCommand)
{
Hidden = true,
DocsLink = DocsLink
};
public readonly Argument<string> SlnOrProjectArgument = CreateSlnOrProjectArgument(CliStrings.SolutionOrProjectArgumentName, CliStrings.SolutionOrProjectArgumentDescription);

command.Arguments.Add(SlnOrProjectArgument);
command.Subcommands.Add(ListPackageCommandDefinition.Create());
command.Subcommands.Add(ListReferenceCommandDefinition.Create());
public readonly ListPackageCommandDefinition PackageCommand = new();
public readonly ListReferenceCommandDefinition ReferenceCommand = new();

public ListCommandDefinition()
: base(Name, CliCommandStrings.NetListCommand)
{
Hidden = true;
this.DocsLink = Link;

return command;
Arguments.Add(SlnOrProjectArgument);
Subcommands.Add(PackageCommand);
Subcommands.Add(ReferenceCommand);
}
}
14 changes: 6 additions & 8 deletions src/Cli/dotnet/Commands/Hidden/List/ListCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.Commands.Hidden.List.Package;
using Microsoft.DotNet.Cli.Commands.Hidden.List.Reference;
using Microsoft.DotNet.Cli.Commands.Package.List;
using Microsoft.DotNet.Cli.Commands.Reference.List;
using Microsoft.DotNet.Cli.Extensions;
Expand All @@ -12,20 +10,20 @@ namespace Microsoft.DotNet.Cli.Commands.Hidden.List;

internal static class ListCommandParser
{
private static readonly Command Command = SetAction(ListCommandDefinition.Create());
private static readonly Command Command = SetAction(new ListCommandDefinition());

public static Command GetCommand()
{
return Command;
}

private static Command SetAction(Command command)
private static Command SetAction(ListCommandDefinition def)
{
command.SetAction(parseResult => parseResult.HandleMissingCommand());
def.SetAction(parseResult => parseResult.HandleMissingCommand());

command.Subcommands.Single(c => c.Name == ListPackageCommandDefinition.Name).SetAction((parseResult) => new PackageListCommand(parseResult).Execute());
command.Subcommands.Single(c => c.Name == ListReferenceCommandDefinition.Name).SetAction((parseResult) => new ReferenceListCommand(parseResult).Execute());
def.PackageCommand.SetAction(parseResult => new PackageListCommand(parseResult).Execute());
def.ReferenceCommand.SetAction(parseResult => new ReferenceListCommand(parseResult).Execute());

return command;
return def;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,12 @@

namespace Microsoft.DotNet.Cli.Commands.Hidden.List.Package;

internal static class ListPackageCommandDefinition
internal sealed class ListPackageCommandDefinition() : PackageListCommandDefinitionBase(Name)
{
public const string Name = "package";
public new const string Name = "package";

public static Command Create()
{
Command command = new(Name, CliCommandStrings.PackageListAppFullName);
public ListCommandDefinition Parent => (ListCommandDefinition)Parents.Single();

command.Options.Add(PackageListCommandDefinition.VerbosityOption);
command.Options.Add(PackageListCommandDefinition.OutdatedOption);
command.Options.Add(PackageListCommandDefinition.DeprecatedOption);
command.Options.Add(PackageListCommandDefinition.VulnerableOption);
command.Options.Add(PackageListCommandDefinition.FrameworkOption);
command.Options.Add(PackageListCommandDefinition.TransitiveOption);
command.Options.Add(PackageListCommandDefinition.PrereleaseOption);
command.Options.Add(PackageListCommandDefinition.HighestPatchOption);
command.Options.Add(PackageListCommandDefinition.HighestMinorOption);
command.Options.Add(PackageListCommandDefinition.ConfigOption);
command.Options.Add(PackageListCommandDefinition.SourceOption);
command.Options.Add(PackageListCommandDefinition.InteractiveOption);
command.Options.Add(PackageListCommandDefinition.FormatOption);
command.Options.Add(PackageListCommandDefinition.OutputVersionOption);
command.Options.Add(PackageListCommandDefinition.NoRestore);

return command;
}
public override string? GetFileOrDirectory(ParseResult parseResult)
=> parseResult.GetValue(Parent.SlnOrProjectArgument);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.Commands.Reference.List;

namespace Microsoft.DotNet.Cli.Commands.Hidden.List.Reference;

internal static class ListReferenceCommandDefinition
internal sealed class ListReferenceCommandDefinition : ListReferenceCommandDefinitionBase
{
public const string Name = "reference";
public new const string Name = "reference";

public static readonly Argument<string> Argument = new("argument") { Arity = ArgumentArity.ZeroOrOne, Hidden = true };
public readonly Argument<string> Argument = new("argument") { Arity = ArgumentArity.ZeroOrOne, Hidden = true };

public static Command Create()
public ListReferenceCommandDefinition() : base(Name)
{
var command = new Command(Name, CliCommandStrings.ReferenceListAppFullName);
Arguments.Add(Argument);
}

public ListCommandDefinition Parent => (ListCommandDefinition)Parents.Single();

command.Arguments.Add(Argument);
internal override string? GetFileOrDirectory(ParseResult parseResult)
=> parseResult.GetValue(Parent.SlnOrProjectArgument);
}

return command;
internal abstract class ListReferenceCommandDefinitionBase : Command
{
public ListReferenceCommandDefinitionBase(string name)
: base(name, CliCommandStrings.ReferenceListAppFullName)
{
}

internal abstract string? GetFileOrDirectory(ParseResult parseResult);
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.Commands.Package.Remove;

namespace Microsoft.DotNet.Cli.Commands.Hidden.Remove.Package;

internal static class RemovePackageCommandDefinition
internal sealed class RemovePackageCommandDefinition() : PackageRemoveCommandDefinitionBase(Name)
{
public const string Name = "package";

public static Command Create()
{
var command = new Command(Name, CliCommandStrings.PackageRemoveAppFullName);

command.Arguments.Add(PackageRemoveCommandDefinition.CmdPackageArgument);
command.Options.Add(PackageRemoveCommandDefinition.InteractiveOption);

return command;
}
public new const string Name = "package";
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@

namespace Microsoft.DotNet.Cli.Commands.Hidden.Remove.Reference;

internal static class RemoveReferenceCommandDefinition
internal sealed class RemoveReferenceCommandDefinition() : ReferenceRemoveCommandDefinitionBase(Name)
{
public const string Name = "reference";
public new const string Name = "reference";

public static Command Create()
{
var command = new Command(Name, CliCommandStrings.ReferenceRemoveAppFullName);
public RemoveCommandDefinition Parent => (RemoveCommandDefinition)Parents.Single();

command.Arguments.Add(ReferenceRemoveCommandDefinition.ProjectPathArgument);
command.Options.Add(ReferenceRemoveCommandDefinition.FrameworkOption);

return command;
}
public override string? GetFileOrDirectory(ParseResult parseResult)
=> parseResult.GetValue(Parent.ProjectOrFileArgument);
}
Loading
Loading