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-17 19:26:52 -08:00
|
|
|
|
using System.Linq;
|
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-17 19:26:52 -08:00
|
|
|
|
throw new ToolConfigurationException(CommonLocalizableStrings.ToolSettingsMissingCommandName);
|
2017-11-21 20:10:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(toolAssemblyEntryPoint))
|
|
|
|
|
{
|
2018-01-17 19:26:52 -08:00
|
|
|
|
throw new ToolConfigurationException(
|
|
|
|
|
string.Format(
|
|
|
|
|
CommonLocalizableStrings.ToolSettingsMissingEntryPoint,
|
|
|
|
|
commandName));
|
2017-11-21 20:10:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 19:26:52 -08:00
|
|
|
|
EnsureNoInvalidFilenameCharacters(commandName);
|
|
|
|
|
|
2017-11-21 20:10:06 -08:00
|
|
|
|
CommandName = commandName;
|
|
|
|
|
ToolAssemblyEntryPoint = toolAssemblyEntryPoint;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 19:26:52 -08:00
|
|
|
|
private void EnsureNoInvalidFilenameCharacters(string commandName)
|
2017-11-21 20:10:06 -08:00
|
|
|
|
{
|
2018-01-17 19:26:52 -08:00
|
|
|
|
var invalidCharacters = Path.GetInvalidFileNameChars();
|
|
|
|
|
if (commandName.IndexOfAny(invalidCharacters) != -1)
|
2017-11-21 20:10:06 -08:00
|
|
|
|
{
|
2018-01-17 19:26:52 -08:00
|
|
|
|
throw new ToolConfigurationException(
|
|
|
|
|
string.Format(
|
|
|
|
|
CommonLocalizableStrings.ToolSettingsInvalidCommandName,
|
|
|
|
|
commandName,
|
|
|
|
|
string.Join(", ", invalidCharacters.Select(c => $"'{c}'"))));
|
2017-11-21 20:10:06 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string CommandName { get; }
|
|
|
|
|
public string ToolAssemblyEntryPoint { get; }
|
|
|
|
|
}
|
|
|
|
|
}
|