dotnet-installer/src/dotnet/ToolPackage/ToolConfiguration.cs
Peter Huene 7ebfdde749
Add verbosity option to install tool command.
This commit adds the `--verbosity` option to the `install tool` command.

MSBuild/NuGet output is now controllable by the user and defaults to being "quiet".

This enables users to see warnings from NuGet that otherwise would be swallowed
unless NuGet returned a non-zero exit code. As a byproduct of this change, the
exception handling and error messages related to obtaining tool packages was
retooled. We no longer display `install tool` command line help for installation
failures, as it should only be displayed for command line syntax errors.

Fixes #8465.
2018-01-31 15:19:34 -08:00

52 lines
1.7 KiB
C#

// 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;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Tools;
namespace Microsoft.DotNet.ToolPackage
{
internal class ToolConfiguration
{
public ToolConfiguration(
string commandName,
string toolAssemblyEntryPoint)
{
if (string.IsNullOrWhiteSpace(commandName))
{
throw new ToolConfigurationException(CommonLocalizableStrings.ToolSettingsMissingCommandName);
}
if (string.IsNullOrWhiteSpace(toolAssemblyEntryPoint))
{
throw new ToolConfigurationException(
string.Format(
CommonLocalizableStrings.ToolSettingsMissingEntryPoint,
commandName));
}
EnsureNoInvalidFilenameCharacters(commandName);
CommandName = commandName;
ToolAssemblyEntryPoint = toolAssemblyEntryPoint;
}
private void EnsureNoInvalidFilenameCharacters(string commandName)
{
var invalidCharacters = Path.GetInvalidFileNameChars();
if (commandName.IndexOfAny(invalidCharacters) != -1)
{
throw new ToolConfigurationException(
string.Format(
CommonLocalizableStrings.ToolSettingsInvalidCommandName,
commandName,
string.Join(", ", invalidCharacters.Select(c => $"'{c}'"))));
}
}
public string CommandName { get; }
public string ToolAssemblyEntryPoint { get; }
}
}