Remove code that moved into CommandLineUtils
This commit is contained in:
parent
849319bcff
commit
13219fafa9
|
|
@ -24,8 +24,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Watcher.To
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Caching.SqlConfig.Tools", "src\Microsoft.Extensions.Caching.SqlConfig.Tools\Microsoft.Extensions.Caching.SqlConfig.Tools.csproj", "{53F3B53D-303A-4DAA-9C38-4F55195FA5B9}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Tools.Tests", "test\Microsoft.Extensions.Tools.Tests\Microsoft.Extensions.Tools.Tests.csproj", "{9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -56,10 +54,6 @@ Global
|
|||
{53F3B53D-303A-4DAA-9C38-4F55195FA5B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{53F3B53D-303A-4DAA-9C38-4F55195FA5B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{53F3B53D-303A-4DAA-9C38-4F55195FA5B9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -71,6 +65,5 @@ Global
|
|||
{7B331122-83B1-4F08-A119-DC846959844C} = {F5B382BC-258F-46E1-AC3D-10E5CCD55134}
|
||||
{8A2E6961-6B12-4A8E-8215-3E7301D52EAC} = {F5B382BC-258F-46E1-AC3D-10E5CCD55134}
|
||||
{53F3B53D-303A-4DAA-9C38-4F55195FA5B9} = {66517987-2A5A-4330-B130-207039378FD4}
|
||||
{9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD} = {F5B382BC-258F-46E1-AC3D-10E5CCD55134}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
|
|
@ -1,107 +0,0 @@
|
|||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Extensions.Tools.Internal
|
||||
{
|
||||
public static class ArgumentEscaper
|
||||
{
|
||||
/// <summary>
|
||||
/// Undo the processing which took place to create string[] args in Main, so that the next process will
|
||||
/// receive the same string[] args.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
|
||||
/// </remarks>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
public static string EscapeAndConcatenate(IEnumerable<string> args)
|
||||
=> string.Join(" ", args.Select(EscapeSingleArg));
|
||||
|
||||
private static string EscapeSingleArg(string arg)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
var needsQuotes = ShouldSurroundWithQuotes(arg);
|
||||
var isQuoted = needsQuotes || IsSurroundedWithQuotes(arg);
|
||||
|
||||
if (needsQuotes)
|
||||
{
|
||||
sb.Append('"');
|
||||
}
|
||||
|
||||
for (int i = 0; i < arg.Length; ++i)
|
||||
{
|
||||
var backslashes = 0;
|
||||
|
||||
// Consume all backslashes
|
||||
while (i < arg.Length && arg[i] == '\\')
|
||||
{
|
||||
backslashes++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i == arg.Length && isQuoted)
|
||||
{
|
||||
// Escape any backslashes at the end of the arg when the argument is also quoted.
|
||||
// This ensures the outside quote is interpreted as an argument delimiter
|
||||
sb.Append('\\', 2 * backslashes);
|
||||
}
|
||||
else if (i == arg.Length)
|
||||
{
|
||||
// At then end of the arg, which isn't quoted,
|
||||
// just add the backslashes, no need to escape
|
||||
sb.Append('\\', backslashes);
|
||||
}
|
||||
else if (arg[i] == '"')
|
||||
{
|
||||
// Escape any preceding backslashes and the quote
|
||||
sb.Append('\\', (2 * backslashes) + 1);
|
||||
sb.Append('"');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Output any consumed backslashes and the character
|
||||
sb.Append('\\', backslashes);
|
||||
sb.Append(arg[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (needsQuotes)
|
||||
{
|
||||
sb.Append('"');
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static bool ShouldSurroundWithQuotes(string argument)
|
||||
{
|
||||
// Don't quote already quoted strings
|
||||
if (IsSurroundedWithQuotes(argument))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only quote if whitespace exists in the string
|
||||
return ContainsWhitespace(argument);
|
||||
}
|
||||
|
||||
private static bool IsSurroundedWithQuotes(string argument)
|
||||
{
|
||||
if (argument.Length <= 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return argument[0] == '"' && argument[argument.Length - 1] == '"';
|
||||
}
|
||||
|
||||
private static bool ContainsWhitespace(string argument)
|
||||
=> argument.IndexOfAny(new [] { ' ', '\t', '\n' }) >= 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// 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 System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.Extensions.Tools.Internal
|
||||
{
|
||||
public static class DotNetMuxer
|
||||
{
|
||||
private const string MuxerName = "dotnet";
|
||||
|
||||
static DotNetMuxer()
|
||||
{
|
||||
MuxerPath = TryFindMuxerPath();
|
||||
}
|
||||
|
||||
public static string MuxerPath { get; }
|
||||
|
||||
public static string MuxerPathOrDefault()
|
||||
=> MuxerPath ?? MuxerName;
|
||||
|
||||
private static string TryFindMuxerPath()
|
||||
{
|
||||
var fileName = MuxerName;
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
fileName += ".exe";
|
||||
}
|
||||
|
||||
var fxDepsFile = AppContext.GetData("FX_DEPS_FILE") as string;
|
||||
|
||||
if (string.IsNullOrEmpty(fxDepsFile))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var muxerDir = new FileInfo(fxDepsFile) // Microsoft.NETCore.App.deps.json
|
||||
.Directory? // (version)
|
||||
.Parent? // Microsoft.NETCore.App
|
||||
.Parent? // shared
|
||||
.Parent; // DOTNET_HOME
|
||||
|
||||
if (muxerDir == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var muxer = Path.Combine(muxerDir.FullName, fileName);
|
||||
return File.Exists(muxer)
|
||||
? muxer
|
||||
: null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// 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 System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Watcher.Internal;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.Tools.Internal;
|
||||
|
||||
namespace Microsoft.DotNet.Watcher
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// 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 System;
|
||||
|
|
@ -9,6 +9,7 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.Tools.Internal;
|
||||
|
||||
namespace Microsoft.DotNet.Watcher.Internal
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.Internal;
|
||||
using Microsoft.Extensions.Tools.Internal;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.Tools.Internal;
|
||||
|
||||
namespace Microsoft.Extensions.SecretManager.Tools.Internal
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// 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 System;
|
||||
|
|
@ -10,7 +10,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Dataflow;
|
||||
using Microsoft.Extensions.Internal;
|
||||
using Microsoft.Extensions.Tools.Internal;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Process.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
<PackageReference Include="xunit" Version="$(XunitVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
// 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 Microsoft.Extensions.Tools.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Tools.Internal;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
// 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 Microsoft.Extensions.Tools.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Extensions.Tools.Tests
|
||||
{
|
||||
public class ArgumentEscaperTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(new[] { "one", "two", "three" }, "one two three")]
|
||||
[InlineData(new[] { "line1\nline2", "word1\tword2" }, "\"line1\nline2\" \"word1\tword2\"")]
|
||||
[InlineData(new[] { "with spaces" }, "\"with spaces\"")]
|
||||
[InlineData(new[] { @"with\backslash" }, @"with\backslash")]
|
||||
[InlineData(new[] { @"""quotedwith\backslash""" }, @"\""quotedwith\backslash\""")]
|
||||
[InlineData(new[] { @"C:\Users\" }, @"C:\Users\")]
|
||||
[InlineData(new[] { @"C:\Program Files\dotnet\" }, @"""C:\Program Files\dotnet\\""")]
|
||||
[InlineData(new[] { @"backslash\""preceedingquote" }, @"backslash\\\""preceedingquote")]
|
||||
public void EscapesArguments(string[] args, string expected)
|
||||
=> Assert.Equal(expected, ArgumentEscaper.EscapeAndConcatenate(args));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\build\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\shared\**\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
<PackageReference Include="xunit" Version="$(XunitVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in New Issue