Skip to content

Commit

Permalink
(GH-984) Detect licensed options in FOSS
Browse files Browse the repository at this point in the history
When an option is passed to open source Chocolatey that is only
available in licensed versions, provide a helpful error message so that
there is reduced confusion for the user.
  • Loading branch information
ferventcoder committed Sep 29, 2016
1 parent 7ea5290 commit 7c4a3be
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ public virtual void handle_validation(ChocolateyConfiguration configuration)
{
throw new ApplicationException("Force dependencies can only be used with force also turned on.");
}

if (!string.IsNullOrWhiteSpace(configuration.Input))
{
var unparsedOptionsAndPackages = configuration.Input.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
if (!configuration.Information.IsLicensedVersion)
{
foreach (var argument in unparsedOptionsAndPackages.or_empty_list_if_null())
{
var arg = argument.to_lower();
if (arg.StartsWith("-dir") || arg.StartsWith("--dir") || arg.StartsWith("-install") || arg.StartsWith("--install"))
{
throw new ApplicationException("It appears you are attempting to use options that may be only available in licensed versions of Chocolatey ('{0}'). Please remove and consult the documentation.".format_with(arg));
}
}
}
}
}

public virtual void help_message(ChocolateyConfiguration configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ public virtual void handle_validation(ChocolateyConfiguration configuration)
{
throw new ApplicationException("Package name is required. Please pass at least one package name to upgrade.");
}

if (configuration.ForceDependencies && !configuration.Force)
{
throw new ApplicationException("Force dependencies can only be used with force also turned on.");
}

if (!string.IsNullOrWhiteSpace(configuration.Input))
{
var unparsedOptionsAndPackages = configuration.Input.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
if (!configuration.Information.IsLicensedVersion)
{
foreach (var argument in unparsedOptionsAndPackages.or_empty_list_if_null())
{
var arg = argument.to_lower();
if (arg.StartsWith("-dir") || arg.StartsWith("--dir") || arg.StartsWith("-install") || arg.StartsWith("--install"))
{
throw new ApplicationException(
"It appears you are attempting to use options that may be only available in licensed versions of Chocolatey ('{0}'). Please remove and consult the documentation.".format_with(arg));
}
}
}
}
}

public virtual void help_message(ChocolateyConfiguration configuration)
Expand Down

0 comments on commit 7c4a3be

Please sign in to comment.