2017-11-21 20:10:06 -08:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-12-04 14:13:24 -08:00
|
|
|
|
using System.IO;
|
2018-01-13 09:40:48 -08:00
|
|
|
|
using Microsoft.DotNet.Tools;
|
2017-11-21 20:10:06 -08:00
|
|
|
|
|
2017-12-04 14:13:24 -08:00
|
|
|
|
namespace Microsoft.DotNet.ToolPackage
|
2017-11-21 20:10:06 -08:00
|
|
|
|
{
|
|
|
|
|
internal class ToolConfiguration
|
|
|
|
|
{
|
|
|
|
|
public ToolConfiguration(
|
|
|
|
|
string commandName,
|
|
|
|
|
string toolAssemblyEntryPoint)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(commandName))
|
|
|
|
|
{
|
2018-01-13 09:40:48 -08:00
|
|
|
|
throw new ArgumentNullException(nameof(commandName), CommonLocalizableStrings.CannotBeNullOrWhitespace);
|
2017-11-21 20:10:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EnsureNoInvalidFilenameCharacters(commandName, nameof(toolAssemblyEntryPoint));
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(toolAssemblyEntryPoint))
|
|
|
|
|
{
|
2018-01-13 09:40:48 -08:00
|
|
|
|
throw new ArgumentNullException(nameof(toolAssemblyEntryPoint), CommonLocalizableStrings.CannotBeNullOrWhitespace);
|
2017-11-21 20:10:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CommandName = commandName;
|
|
|
|
|
ToolAssemblyEntryPoint = toolAssemblyEntryPoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EnsureNoInvalidFilenameCharacters(string commandName, string nameOfParam)
|
|
|
|
|
{
|
2017-12-04 14:13:24 -08:00
|
|
|
|
char[] invalidCharactors = Path.GetInvalidFileNameChars();
|
2017-11-21 20:10:06 -08:00
|
|
|
|
if (commandName.IndexOfAny(invalidCharactors) != -1)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException(
|
|
|
|
|
paramName: nameof(nameOfParam),
|
2018-01-13 09:40:48 -08:00
|
|
|
|
message: string.Format(CommonLocalizableStrings.ContainInvalidCharacters,
|
|
|
|
|
new string(invalidCharactors)));
|
2017-11-21 20:10:06 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string CommandName { get; }
|
|
|
|
|
public string ToolAssemblyEntryPoint { get; }
|
|
|
|
|
}
|
|
|
|
|
}
|