chocolatey / choco

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

Choco new silentargs can't pass in args in the param=value format #510

Closed derek-robinson closed 8 years ago

derek-robinson commented 8 years ago

Some applications like Operations Manager use a similar format to choco new to do pass in their arguments, e.g. USE_SETTINGS_FROM_AD={0|1} . (https://technet.microsoft.com/en-us/library/hh230736.aspx)

Creating a new package from template with silentarg="/qn /norestart USE_SETTINGS_FROM_AD=0" will create an emtpy string in the chocolateyInstall.ps1 file. I've tried quoting it several different ways (double quotes, single quotes, double quotes around single quotes, etc).

silentArgs    = ""

This is using Chocolatey v0.9.10-beta1

ferventcoder commented 8 years ago

Interesting.

This is in the template? What exactly does it look like?

Like this?

silentarg="/qn /norestart USE_SETTINGS_FROM_AD=0"
ferventcoder commented 8 years ago

and how are you calling choco new?

ferventcoder commented 8 years ago

Ooooh, wait - choco new silentargs="/qn /norestart USE_SETTINGS_FROM_AD=0"?

ferventcoder commented 8 years ago

To pass arguments with spaces - https://github.com/chocolatey/choco/wiki/CommandsReference#how-to-pass-options--switches

tl;dr:

Depending on whether you are running the command from powershell.exe or cmd.exe, this is how you should pass it: choco new silentargs="'/qn /norestart USE_SETTINGS_FROM_AD=0'" - That is double quotes surrounding apostrophes. Shells make things harder than they need to be sometimes. :/

ferventcoder commented 8 years ago

I think you also brought to light that in the default template this is broken - if you create a template and drop it into a template location as a replacement - add the SilentArgs back in as

[[SilentArgs]] - that's what choco uses for template replacement.

derek-robinson commented 8 years ago

Running that command with the apostrophes in double quotes doesn't succeed in either cmd or powershell.

choco new scom --template embedded silentargs="'/qn /norestart USE_SETTINGS_FROM_AD=0'"

In my template, I had added the [[SilentArgs]]:

$packageArgs = @{
  packageName   = $packageName
  file          = $fileLocation
  fileType      = '[[InstallerType]]' #only one of these: exe, msi, msu

  silentArgs    = "[[SilentArgs]]"
  validExitCodes= @(0, 3010, 1641)
}

Result

$packageArgs = @{
  packageName   = $packageName
  file          = $fileLocation
  fileType      = 'EXE_MSI_OR_MSU' #only one of these: exe, msi, msu

  silentArgs    = ""
  validExitCodes= @(0, 3010, 1641)
}

This template succeeds if I don't pass the = operator.

choco new scom --template embedded silentargs="/qn /norestart USE_SETTINGS_FROM_AD 0"
$packageArgs = @{
  packageName   = $packageName
  file          = $fileLocation
  fileType      = 'EXE_MSI_OR_MSU' #only one of these: exe, msi, msu

  silentArgs    = "/qn /norestart USE_SETTINGS_FROM_AD 0"
  validExitCodes= @(0, 3010, 1641)
}
ferventcoder commented 8 years ago

I'm going to try with -d --noop specified. That is a good way to see what it is actually assigning where.

ferventcoder commented 8 years ago

It's a bug.

ferventcoder commented 8 years ago

The code splits on =, so that will definitely need to get corrected. Thanks for filing an issue!

ferventcoder commented 8 years ago

Do you have a workaround for now?

derek-robinson commented 8 years ago

Yeah, we have a workaround. All I have to do is manually edit the file before packing it. It breaks completely automating the package creation process , but I'm sure I can make something work in powershell to do the same thing until it gets resolved.

derek-robinson commented 8 years ago

Thanks for looking into it! I was sure I was going crazy there for a while.

ferventcoder commented 8 years ago

Almost fully automated package creation, you will have to tell me about that sometime :+1:

sahebjade commented 8 years ago

I have created Pull Request #513 to fix the issue. if you like the fix, please can you merge. Thanks https://travis-ci.org/chocolatey/choco/builds/98298512

ferventcoder commented 8 years ago

The missing SilentArgs template value has been missing since 0.9.9.7 - 7b468c8e6ff41913c5fa29499d2ad8cb681a96cb was the commit that introduced the regression.

ferventcoder commented 8 years ago

I've added the fix for allowing silentargs again in the default template. I see @sahebjade has created a PR to fix the = issue. I've added comments to the PR, if you wouldn't mind looking at those and making adjustments. Thanks!

ferventcoder commented 8 years ago

Thanks! I just rebased this to stable and updated the commit message. This will go out in the next beta release in a couple of hours.