chocolatey / choco

Chocolatey - the package manager for Windows
https://chocolatey.org
Other
10.06k stars 891 forks source link

Commandline arguments parsed improperly #1639

Open hadek314 opened 5 years ago

hadek314 commented 5 years ago

What You Are Seeing?

In my nuspec I have variables:

$src$ and $bin$

It looks like this:


<file src="$src$\tools\chocolateyInstall.ps1" target="tools"/>

    <file src="$src$\tools\chocolateyUninstall.ps1" target="tools"/>

    <file src="$bin$\bin\**\*" target="bin-service"/>

What is Expected?

Running this:

choco pack filename.nuspec

Generates error:

The replacement token 'src' has no value

However this:

choco pack filename.nuspec src="testpath"

Generates error:

File specified is either not found or not a .nuspec file. 'filename.nuspec src=testpath'

Adding any other flag between nuspec file name and parameter does not change the error. For example:

choco pack filename.nuspec --version 0.0.3 src="testpath"

generates the same error.

Note that parser picks out '--' variable but then concatenates the nuspec file name and key=val as if the combined string was the complete path to nuspec file.

Output Log

SourceType='normal'|Debug='True'|Verbose='False'|Trace='False'|

Force='False'|Noop='False'|HelpRequested='False'|

UnsuccessfulParsing='False'|RegularOutput='True'|QuietOutput='False'|

PromptForConfirmation='False'|AcceptLicense='False'|

AllowUnofficialBuild='False'|

Input='filename.nuspec src=testpath'|Version='0.0.3'|

AllVersions='False'|SkipPackageInstallProvider='False'|

Prerelease='False'|ForceX86='False'|OverrideArguments='False'|

NotSilent='False'|ApplyPackageParametersToDependencies='False'|

ApplyInstallArgumentsToDependencies='False'|IgnoreDependencies='False'|

AllowMultipleVersions='False'|AllowDowngrade='False'|

ForceDependencies='False'|Information.PlatformType='Windows'|

Information.PlatformVersion='6.3.9600.0'|

Information.PlatformName='Windows Server 2012 R2'|

Information.ChocolateyVersion='0.10.5.0'|

Information.ChocolateyProductVersion='0.10.5'|

Information.FullName='choco, Version=0.10.5.0, Culture=neutral, PublicKeyToken=79d02ea9cad655eb'|

Information.Is64BitOperatingSystem='True'|

Information.Is64BitProcess='True'|Information.IsInteractive='True'|

Information.IsUserAdministrator='True'|

Information.IsProcessElevated='True'|

Information.IsLicensedVersion='False'|Information.LicenseType='Foss'|

Features.AutoUninstaller='True'|Features.ChecksumFiles='True'|

Features.AllowEmptyChecksums='False'|

Features.AllowEmptyChecksumsSecure='True'|

Features.FailOnAutoUninstaller='False'|

Features.FailOnStandardError='False'|Features.UsePowerShellHost='True'|

Features.LogEnvironmentValues='False'|Features.VirusCheck='False'|

Features.FailOnInvalidOrMissingLicense='False'|

Features.IgnoreInvalidOptionsSwitches='True'|

Features.UsePackageExitCodes='True'|

Features.UseFipsCompliantChecksums='False'|

Features.ShowNonElevatedWarnings='True'|

Features.ShowDownloadProgress='True'|

Features.StopOnFirstPackageFailure='False'|

Features.UseRememberedArgumentsForUpgrades='False'|

Features.ScriptsCheckLastExitCode='False'|

ListCommand.LocalOnly='False'|

ListCommand.IncludeRegistryPrograms='False'|ListCommand.PageSize='25'|

ListCommand.Exact='False'|ListCommand.ByIdOnly='False'|

ListCommand.IdStartsWith='False'|ListCommand.OrderByPopularity='False'|

ListCommand.ApprovedOnly='False'|

ListCommand.DownloadCacheAvailable='False'|

ListCommand.NotBroken='False'|

ListCommand.IncludeVersionOverrides='False'|

UpgradeCommand.FailOnUnfound='False'|

UpgradeCommand.FailOnNotInstalled='False'|

UpgradeCommand.NotifyOnlyAvailableUpgrades='False'|

UpgradeCommand.ExcludePrerelease='False'|

NewCommand.AutomaticPackage='False'|

NewCommand.UseOriginalTemplate='False'|SourceCommand.Command='unknown'|

SourceCommand.Priority='0'|SourceCommand.BypassProxy='False'|

SourceCommand.AllowSelfService='False'|

FeatureCommand.Command='unknown'|

ConfigCommand.Command='unknown'|PinCommand.Command='unknown'|

Proxy.BypassOnLocal='True'|

Chocolatey:ChocolateyPackCommand - Normal Run Mode

Chocolatey had an error occur:

System.ArgumentException: File specified is either not found or not a .nuspec file. 'clientreporting-service.nuspec src=

testpath'

at chocolatey.infrastructure.app.services.NugetService.<>cDisplayClass23.b22(St

ring name, String value)

at chocolatey.infrastructure.guards.Ensure1.meets(Func2 ensureFunction, Action`2 exceptionAction)

at chocolatey.infrastructure.app.services.NugetService.validate_and_return_package_file(ChocolateyConfiguration confi

g, String extension)

at chocolatey.infrastructure.app.services.NugetService.pack_run(ChocolateyConfiguration config)

at chocolatey.infrastructure.app.services.ChocolateyPackageService.pack_run(ChocolateyConfiguration config)

at chocolatey.infrastructure.app.runners.GenericRunner.run(ChocolateyConfiguration config, Container container, Boole

an isConsole, Action`1 parseArgs)

at chocolatey.infrastructure.app.runners.ConsoleApplication.run(String[] args, ChocolateyConfiguration config, Contai

ner container)

at chocolatey.console.Program.Main(String[] args)

hadek314 commented 5 years ago

I'm going to close this issue but maybe someone needs to take a look at it later and/or handle errors better. It turned out that nuspec had the following string for version "1.1.x". When launched 'pack' like this: choco pack filename.nuspec the first error it presented was about lack of $src$ substitution. When I provided substitution to $src$ and $bin$ the error should have been that XML Element "version" was invalid. Instead it was presenting error with strangely concatenated nuspec name.

Bottom line there is a bug but it's in error handling when XML element value is not valid.

gep13 commented 5 years ago

@hadek314 in case someone gets a chance to look at this, can you please provide a sample nuspec that illustrates the problem that you are seeing?