From: Mike McLaughlin Date: Sat, 23 Feb 2019 20:23:38 +0000 (-0800) Subject: Get dotnet-sos syntax up to spec. X-Git-Tag: submit/tizen/20190813.035844~53^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=abc8e64333aaec6a0e1b36eede9c99995530862f;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Get dotnet-sos syntax up to spec. --- diff --git a/src/Tools/dotnet-sos/Program.cs b/src/Tools/dotnet-sos/Program.cs index ddbb64f28..27dbd50c5 100644 --- a/src/Tools/dotnet-sos/Program.cs +++ b/src/Tools/dotnet-sos/Program.cs @@ -1,64 +1,58 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using McMaster.Extensions.CommandLineUtils; using SOS; using System; +using System.CommandLine; +using System.CommandLine.Builder; +using System.CommandLine.Invocation; using System.Threading.Tasks; namespace Microsoft.Diagnostics.Tools.SOS { - [Command(Name = "dotnet-sos", Description = "Install and configure SOS")] - internal class Program + public class Program { - [Option("--install", Description = "Install and configure SOS.")] - public bool InstallSOS { get; set; } + public static Task Main(string[] args) + { + var parser = new CommandLineBuilder() + .AddCommand(InstallCommand()) + .AddCommand(UninstallCommand()) + .UseDefaults() + .Build(); - [Option("--uninstall", Description = "Uninstall SOS.")] - public bool UninstallSOS { get; set; } + return parser.InvokeAsync(args); + } - [Option("--source", Description = "SOS binaries source path.")] - public string SOSSourcePath { get; set; } + private static Command InstallCommand() => + new Command( + "install", + "Installs SOS and configures LLDB to load it on startup.", + handler: CommandHandler.Create((console) => InvokeAsync(console, install: true))); - public int OnExecute(IConsole console, CommandLineApplication app) - { - if (InstallSOS || UninstallSOS) - { - try - { - var sosInstaller = new InstallHelper((message) => console.WriteLine(message)); - if (SOSSourcePath != null) - { - sosInstaller.SOSSourcePath = SOSSourcePath; - } - if (UninstallSOS) - { - sosInstaller.Uninstall(); - } - else - { - sosInstaller.Install(); - } - } - catch (SOSInstallerException ex) - { - console.Error.WriteLine(ex.Message); - return 1; - } - } - return 0; - } + private static Command UninstallCommand() => + new Command( + "uninstall", + "Uninstalls SOS and reverts any configuration changes to LLDB.", + handler: CommandHandler.Create((console) => InvokeAsync(console, install: false))); - private static int Main(string[] args) + private static Task InvokeAsync(IConsole console, bool install) { try { - return CommandLineApplication.Execute(args); + var sosInstaller = new InstallHelper((message) => console.Out.WriteLine(message)); + if (install) { + sosInstaller.Install(); + } + else { + sosInstaller.Uninstall(); + } } - catch (OperationCanceledException) + catch (SOSInstallerException ex) { - return 0; + console.Error.WriteLine(ex.Message); + return Task.FromResult(1); } + return Task.FromResult(0); } } } diff --git a/src/Tools/dotnet-sos/dotnet-sos.csproj b/src/Tools/dotnet-sos/dotnet-sos.csproj index cb4238a60..3a0ed60bf 100644 --- a/src/Tools/dotnet-sos/dotnet-sos.csproj +++ b/src/Tools/dotnet-sos/dotnet-sos.csproj @@ -23,13 +23,13 @@ - + - + - + - + <_PackageFiles Include="$(SOSNETCoreBinaries)"> None