@@ -37,11 +37,19 @@ public class ChocolateyExportCommand : ICommand
3737 {
3838 private readonly INugetService _nugetService ;
3939 private readonly IFileSystem _fileSystem ;
40-
41- public ChocolateyExportCommand ( INugetService nugetService , IFileSystem fileSystem )
40+ private readonly IChocolateyPackageInformationService _packageInfoService ;
41+ private readonly IChocolateyPackageService _packageService ;
42+
43+ public ChocolateyExportCommand (
44+ INugetService nugetService ,
45+ IFileSystem fileSystem ,
46+ IChocolateyPackageInformationService packageInfoService ,
47+ IChocolateyPackageService packageService )
4248 {
4349 _nugetService = nugetService ;
4450 _fileSystem = fileSystem ;
51+ _packageInfoService = packageInfoService ;
52+ _packageService = packageService ;
4553 }
4654
4755 public void ConfigureArgumentParser ( OptionSet optionSet , ChocolateyConfiguration configuration )
@@ -53,6 +61,9 @@ public void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfiguration
5361 . Add ( "include-version-numbers|include-version" ,
5462 "Include Version Numbers - controls whether or not version numbers for each package appear in generated file. Defaults to false." ,
5563 option => configuration . ExportCommand . IncludeVersionNumbers = option != null )
64+ . Add ( "include-arguments|include-remembered-arguments" ,
65+ "Include Remembered Arguments - controls whether or not remembered arguments for each package appear in generated file. Defaults to false. Available in 2.3.0+" ,
66+ option => configuration . ExportCommand . IncludeRememberedPackageArguments = option != null )
5667 ;
5768 }
5869
@@ -96,12 +107,14 @@ choco export [<options/switches>]
96107 "chocolatey" . Log ( ) . Info ( @"
97108 choco export
98109 choco export --include-version-numbers
110+ choco export --include-version-numbers --include-remembered-arguments
99111 choco export ""'c:\temp\packages.config'""
100112 choco export ""'c:\temp\packages.config'"" --include-version-numbers
101113 choco export -o=""'c:\temp\packages.config'""
102114 choco export -o=""'c:\temp\packages.config'"" --include-version-numbers
103115 choco export --output-file-path=""'c:\temp\packages.config'""
104116 choco export --output-file-path=""'c:\temp\packages.config'"" --include-version-numbers
117+ choco export --output-file-path=""""'c:\temp\packages.config'"""" --include-remembered-arguments
105118
106119NOTE: See scripting in the command reference (`choco -?`) for how to
107120 write proper scripts and integrations.
@@ -132,14 +145,16 @@ public bool MayRequireAdminAccess()
132145
133146 public void DryRun ( ChocolateyConfiguration configuration )
134147 {
135- this . Log ( ) . Info ( "Export would have been with options: {0} Output File Path={1}{0} Include Version Numbers:{2}" . FormatWith ( Environment . NewLine , configuration . ExportCommand . OutputFilePath , configuration . ExportCommand . IncludeVersionNumbers ) ) ;
148+ this . Log ( ) . Info ( "Export would have been with options: {0} Output File Path={1}{0} Include Version Numbers:{2}{0} Include Remembered Arguments: {3} " . FormatWith ( Environment . NewLine , configuration . ExportCommand . OutputFilePath , configuration . ExportCommand . IncludeVersionNumbers , configuration . ExportCommand . IncludeRememberedPackageArguments ) ) ;
136149 }
137150
138151 public void Run ( ChocolateyConfiguration configuration )
139152 {
140153 var installedPackages = _nugetService . GetInstalledPackages ( configuration ) ;
141154 var xmlWriterSettings = new XmlWriterSettings { Indent = true , Encoding = new UTF8Encoding ( false ) } ;
142155
156+ configuration . CreateBackup ( ) ;
157+
143158 FaultTolerance . TryCatchWithLoggingException (
144159 ( ) =>
145160 {
@@ -162,6 +177,40 @@ public void Run(ChocolateyConfiguration configuration)
162177 packageElement . Version = packageResult . PackageMetadata . Version . ToString ( ) ;
163178 }
164179
180+ if ( configuration . ExportCommand . IncludeRememberedPackageArguments )
181+ {
182+ var pkgInfo = _packageInfoService . Get ( packageResult . PackageMetadata ) ;
183+ configuration . Features . UseRememberedArgumentsForUpgrades = true ;
184+ var rememberedConfig = _nugetService . GetPackageConfigFromRememberedArguments ( configuration , pkgInfo ) ;
185+
186+ // Mirrors the arguments captured in ChocolateyPackageService.CaptureArguments()
187+ if ( configuration . Prerelease ) packageElement . Prerelease = true ;
188+ if ( configuration . IgnoreDependencies ) packageElement . IgnoreDependencies = true ;
189+ if ( configuration . ForceX86 ) packageElement . ForceX86 = true ;
190+ if ( ! string . IsNullOrWhiteSpace ( configuration . InstallArguments ) ) packageElement . InstallArguments = configuration . InstallArguments ;
191+ if ( configuration . OverrideArguments ) packageElement . OverrideArguments = true ;
192+ if ( configuration . ApplyInstallArgumentsToDependencies ) packageElement . ApplyInstallArgumentsToDependencies = true ;
193+ if ( ! string . IsNullOrWhiteSpace ( configuration . PackageParameters ) ) packageElement . PackageParameters = configuration . PackageParameters ;
194+ if ( configuration . ApplyPackageParametersToDependencies ) packageElement . ApplyPackageParametersToDependencies = true ;
195+ if ( configuration . AllowDowngrade ) packageElement . AllowDowngrade = true ;
196+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Username ) ) packageElement . User = configuration . SourceCommand . Username ;
197+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Password ) ) packageElement . Password = configuration . SourceCommand . Password ;
198+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Certificate ) ) packageElement . Cert = configuration . SourceCommand . Certificate ;
199+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . CertificatePassword ) ) packageElement . CertPassword = configuration . SourceCommand . CertificatePassword ;
200+ // Arguments from the global options set
201+ if ( configuration . CommandExecutionTimeoutSeconds != ApplicationParameters . DefaultWaitForExitInSeconds )
202+ {
203+ packageElement . ExecutionTimeout = configuration . CommandExecutionTimeoutSeconds ;
204+ }
205+ // This was discussed in the PR, and because it is potentially system specific, it should not be included in the exported file
206+ // if (!string.IsNullOrWhiteSpace(configuration.CacheLocation)) packageElement.CacheLocation = configuration.CacheLocation;
207+ // if (configuration.Features.FailOnStandardError) packageElement.FailOnStderr = true;
208+ // if (!configuration.Features.UsePowerShellHost) packageElement.UseSystemPowershell = true;
209+
210+ // Make sure to reset the configuration so as to be able to parse the next set of remembered arguments
211+ configuration . RevertChanges ( ) ;
212+ }
213+
165214 packagesConfig . Packages . Add ( packageElement ) ;
166215 }
167216
0 commit comments