<commit_before>﻿using NuKeeper.ProcessRunner;
using System;
using System.IO;
using System.Threading.Tasks;
using NuGet.Versioning;
using NuKeeper.RepositoryInspection;

namespace NuKeeper.NuGet.Process
{
    public class PackagesConfigUpdater : INuGetUpdater
    {
        private readonly IExternalProcess _externalProcess;

        public PackagesConfigUpdater(IExternalProcess externalProcess = null)
        {
            _externalProcess = externalProcess ?? new ExternalProcess();
        }

        public async Task UpdatePackage(NuGetVersion newVersion, PackageInProject currentPackage)
        {
            var dirName = currentPackage.Path.FullDirectory;
            var nuget = GetNuGetPath();
            var updateCommand = $"cd {dirName}"
                + $" & {nuget} restore packages.config"
                + $" & {nuget} update packages.config -Id {currentPackage.Id} -Version {newVersion}";
            Console.WriteLine(updateCommand);
            await RunExternalCommand(updateCommand);
        }

        private async Task RunExternalCommand(string command)
        {
            var result = await _externalProcess.Run(command);

            if (!result.Success)
            {
                throw new Exception($"Exit code: {result.ExitCode}\n\n{result.Output}\n\n{result.ErrorOutput}");
            }
        }

        private string GetNuGetPath()
        {
            var profile = Environment.GetEnvironmentVariable("userprofile");

            return Path.GetFullPath(Path.Combine(profile, ".nuget\\packages\\nuget.commandline\\4.1.0\\tools\\NuGet.exe"));
        }
    }
}<commit_msg>Better error message when this tool is not found<commit_after>﻿using NuKeeper.ProcessRunner;
using System;
using System.IO;
using System.Threading.Tasks;
using NuGet.Versioning;
using NuKeeper.RepositoryInspection;

namespace NuKeeper.NuGet.Process
{
    public class PackagesConfigUpdater : INuGetUpdater
    {
        private readonly IExternalProcess _externalProcess;

        public PackagesConfigUpdater(IExternalProcess externalProcess = null)
        {
            _externalProcess = externalProcess ?? new ExternalProcess();
        }

        public async Task UpdatePackage(NuGetVersion newVersion, PackageInProject currentPackage)
        {
            var dirName = currentPackage.Path.FullDirectory;
            var nuget = GetNuGetPath();
            var updateCommand = $"cd {dirName}"
                + $" & {nuget} restore packages.config"
                + $" & {nuget} update packages.config -Id {currentPackage.Id} -Version {newVersion}";
            Console.WriteLine(updateCommand);
            await RunExternalCommand(updateCommand);
        }

        private async Task RunExternalCommand(string command)
        {
            var result = await _externalProcess.Run(command);

            if (!result.Success)
            {
                throw new Exception($"Exit code: {result.ExitCode}\n\n{result.Output}\n\n{result.ErrorOutput}");
            }
        }

        private string GetNuGetPath()
        {
            var profile = Environment.GetEnvironmentVariable("userprofile");
            var nugetDir = Path.Combine(profile, ".nuget\\packages\\nuget.commandline\\4.1.0\\tools");

            if (!Directory.Exists(nugetDir))
            {
                throw new Exception("Could not find nuget commandline path: " + nugetDir);
            }

            return Path.GetFullPath(Path.Combine(nugetDir, "NuGet.exe"));
        }
    }
}
{'fraction_non_alphanumeric': 0.09522447812410638, 'fraction_numerical': 0.0017157563625965113, 'mean_word_length': 2.3764478764478763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1207754', 'n_tokens_mistral': 934, 'n_tokens_neox': 901, 'n_words': 193}