Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-1562) Fix: --version includes warnings/errors
  (GH-1724) search - exit 1 on no results
  (GH-1614) Fix: quote if pipe found in string
  • Loading branch information
ferventcoder committed Mar 12, 2019
2 parents 2c273d3 + 35e9f81 commit faaf3e5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/chocolatey/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,20 @@ public static string escape_curly_braces(this string input)

return open_brace_regex.Replace(close_brace_regex.Replace(input,"}}"),"{{");
}

/// <summary>
/// Surrounds with quotes if a pipe is found in the input string.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>The input, but with double quotes if there is a pipe character found in the string.</returns>
public static string quote_if_pipe_found(this string input)
{
if (string.IsNullOrWhiteSpace(input)) return input.to_string();

if (input.contains("|")) return "\"{0}\"".format_with(input);

return input;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace chocolatey.infrastructure.app.commands
{
using System;
using System.Collections.Generic;
using System.Linq;
using attributes;
Expand Down Expand Up @@ -201,7 +202,13 @@ public virtual void run(ChocolateyConfiguration configuration)
{
_packageService.ensure_source_app_installed(configuration);
// note: you must leave the .ToList() here or else the method won't be evaluated!
_packageService.list_run(configuration).ToList();
var packageResults = _packageService.list_run(configuration).ToList();

// if there are no results, exit with a 1.
if (packageResults.Count == 0)
{
Environment.ExitCode = 1;
}
}

public virtual IEnumerable<PackageResult> list(ChocolateyConfiguration configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public virtual IEnumerable<ChocolateySource> source_list(ChocolateyConfiguration
source.Id,
source.Value,
source.Disabled.to_string(),
source.UserName,
source.UserName.quote_if_pipe_found(),
source.Certificate,
source.Priority,
source.BypassProxy.to_string(),
Expand Down
23 changes: 18 additions & 5 deletions src/chocolatey/infrastructure/licensing/LicenseValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static ChocolateyLicense validate()
LicenseType = ChocolateyLicenseType.Unknown
};

var regularLogOutput = determine_if_regular_output_for_logging();

string licenseFile = ApplicationParameters.LicenseFileLocation;
var userLicenseFile = ApplicationParameters.UserLicenseFileLocation;
if (File.Exists(userLicenseFile)) licenseFile = userLicenseFile;
Expand All @@ -50,7 +52,7 @@ public static ChocolateyLicense validate()
{
if (Directory.GetFiles(licenseDirectory).Length != 0)
{
"chocolatey".Log().Error(@"Files found in directory '{0}' but not a
"chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, @"Files found in directory '{0}' but not a
valid license file. License should be named '{1}'.".format_with(licenseDirectory, licenseFileName));
"chocolatey".Log().Warn(ChocolateyLoggers.Important,@" Rename license file to '{0}' to allow commercial features.".format_with(licenseFileName));
}
Expand All @@ -60,9 +62,9 @@ public static ChocolateyLicense validate()
// - user put the license file in the top level location and/or forgot to rename it
if (File.Exists(Path.Combine(ApplicationParameters.InstallLocation, licenseFileName)) || File.Exists(Path.Combine(ApplicationParameters.InstallLocation, licenseFileName + ".txt")))
{
"chocolatey".Log().Error(@"Chocolatey license found in the wrong location. File must be located at
"chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, @"Chocolatey license found in the wrong location. File must be located at
'{0}'.".format_with(ApplicationParameters.LicenseFileLocation));
"chocolatey".Log().Warn(ChocolateyLoggers.Important, @" Move license file to '{0}' to allow commercial features.".format_with(ApplicationParameters.LicenseFileLocation));
"chocolatey".Log().Warn(regularLogOutput ? ChocolateyLoggers.Important : ChocolateyLoggers.LogFileOnly, @" Move license file to '{0}' to allow commercial features.".format_with(ApplicationParameters.LicenseFileLocation));
}
}

Expand All @@ -88,15 +90,15 @@ public static ChocolateyLicense validate()
{
chocolateyLicense.IsValid = false;
chocolateyLicense.InvalidReason = e.Message;
"chocolatey".Log().Error("A license was not found for a licensed version of Chocolatey:{0} {1}{0} {2}".format_with(Environment.NewLine, e.Message,
"chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, "A license was not found for a licensed version of Chocolatey:{0} {1}{0} {2}".format_with(Environment.NewLine, e.Message,
"A license was also not found in the user profile: '{0}'.".format_with(ApplicationParameters.UserLicenseFileLocation)));
}
catch (Exception e)
{
//license may be invalid
chocolateyLicense.IsValid = false;
chocolateyLicense.InvalidReason = e.Message;
"chocolatey".Log().Error("A license was found for a licensed version of Chocolatey, but is invalid:{0} {1}".format_with(Environment.NewLine, e.Message));
"chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, "A license was found for a licensed version of Chocolatey, but is invalid:{0} {1}".format_with(Environment.NewLine, e.Message));
}

var chocolateyLicenseType = ChocolateyLicenseType.Unknown;
Expand Down Expand Up @@ -134,5 +136,16 @@ public static ChocolateyLicense validate()

return chocolateyLicense;
}

private static bool determine_if_regular_output_for_logging()
{
var args = Environment.GetCommandLineArgs();
if (args == null || args.Length < 2) return true;

var firstArg = args[1].to_string();
if (firstArg.is_equal_to("-v") || firstArg.is_equal_to("--version")) return false;

return true;
}
}
}

0 comments on commit faaf3e5

Please sign in to comment.