@@ -36,11 +36,14 @@ public class ChocolateyExportCommand : ICommand
3636    { 
3737        private  readonly  INugetService  _nugetService ; 
3838        private  readonly  IFileSystem  _fileSystem ; 
39+         private  readonly  IChocolateyPackageInformationService  _packageInfoService ; 
40+         private  readonly  IChocolateyPackageService  _packageService ; 
3941
40-         public  ChocolateyExportCommand ( INugetService  nugetService ,  IFileSystem  fileSystem ) 
42+         public  ChocolateyExportCommand ( INugetService  nugetService ,  IFileSystem  fileSystem ,   IChocolateyPackageInformationService   packageInfoService ) 
4143        { 
4244            _nugetService  =  nugetService ; 
4345            _fileSystem  =  fileSystem ; 
46+             _packageInfoService  =  packageInfoService ; 
4447        } 
4548
4649        public  void  configure_argument_parser ( OptionSet  optionSet ,  ChocolateyConfiguration  configuration ) 
@@ -52,6 +55,9 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati
5255                . Add ( "include-version-numbers|include-version" , 
5356                     "Include Version Numbers - controls whether or not version numbers for each package appear in generated file.  Defaults to false." , 
5457                     option =>  configuration . ExportCommand . IncludeVersionNumbers  =  option  !=  null ) 
58+                 . Add ( "include-arguments|include-remembered-arguments" , 
59+                     "Include Remembered Arguments - controls whether or not remembered arguments for each package appear in generated file.  Defaults to false." , 
60+                     option =>  configuration . ExportCommand . IncludeRememberedPackageArguments  =  option  !=  null ) 
5561                ; 
5662        } 
5763
@@ -97,12 +103,14 @@ choco export [<options/switches>]
97103            "chocolatey" . Log ( ) . Info ( @" 
98104    choco export 
99105    choco export --include-version-numbers 
106+     choco export --include-version-numbers --include-remembered-arguments 
100107    choco export ""'c:\temp\packages.config'"" 
101108    choco export ""'c:\temp\packages.config'"" --include-version-numbers 
102109    choco export -o=""'c:\temp\packages.config'"" 
103110    choco export -o=""'c:\temp\packages.config'"" --include-version-numbers 
104111    choco export --output-file-path=""'c:\temp\packages.config'"" 
105112    choco export --output-file-path=""'c:\temp\packages.config'"" --include-version-numbers 
113+     choco export --output-file-path=""'c:\temp\packages.config'"" --include-remembered-arguments 
106114
107115NOTE: See scripting in the command reference (`choco -?`) for how to 
108116 write proper scripts and integrations. 
@@ -133,13 +141,24 @@ public bool may_require_admin_access()
133141
134142        public  void  noop ( ChocolateyConfiguration  configuration ) 
135143        { 
136-             this . Log ( ) . Info ( "Export would have been with options: {0} Output File Path={1}{0} Include Version Numbers:{2}" . format_with ( Environment . NewLine ,  configuration . ExportCommand . OutputFilePath ,  configuration . ExportCommand . IncludeVersionNumbers ) ) ; 
144+             this . Log ( ) . Info ( "Export would have been with options: {0} Output File Path={1}{0} Include Version Numbers:{2}{0} Include Remembered Arguments: {3} " . format_with ( Environment . NewLine ,  configuration . ExportCommand . OutputFilePath ,  configuration . ExportCommand . IncludeVersionNumbers ,   configuration . ExportCommand . IncludeRememberedPackageArguments ) ) ; 
137145        } 
138146
139147        public  void  run ( ChocolateyConfiguration  configuration ) 
140148        { 
141149            var  packageResults  =  _nugetService . get_all_installed_packages ( configuration ) ; 
142150            var  settings  =  new  XmlWriterSettings  {  Indent  =  true ,  Encoding  =  new  UTF8Encoding ( false )  } ; 
151+             var  originalConfiguration  =  configuration . deep_copy ( ) ; 
152+ 
153+             if  ( configuration . ExportCommand . IncludeRememberedPackageArguments ) 
154+             { 
155+                 // The -o argument from the export command options set interferes with the -o argument from the install command options set. 
156+                 ConfigurationOptions . OptionSet . Remove ( "o" ) ; 
157+ 
158+                 //Add the options set from the install command. 
159+                 var  installCommand  =  new  ChocolateyInstallCommand ( _packageService ) ; 
160+                 installCommand . configure_argument_parser ( ConfigurationOptions . OptionSet ,  configuration ) ; 
161+             } 
143162
144163            FaultTolerance . try_catch_with_logging_exception ( 
145164                ( )  => 
@@ -161,6 +180,49 @@ public void run(ChocolateyConfiguration configuration)
161180                                    xw . WriteAttributeString ( "version" ,  packageResult . Package . Version . ToString ( ) ) ; 
162181                                } 
163182
183+                                 if  ( configuration . ExportCommand . IncludeRememberedPackageArguments ) 
184+                                 { 
185+                                     var  pkgInfo  =  _packageInfoService . get_package_information ( packageResult . Package ) ; 
186+                                     configuration . Features . UseRememberedArgumentsForUpgrades  =  true ; 
187+                                     _nugetService . set_package_config_for_upgrade ( configuration ,  pkgInfo ) ; 
188+ 
189+                                     //Mirrors the arguments captured in ChocolateyPackageService.capture_arguments() 
190+ 
191+                                     if  ( configuration . Prerelease )  xw . WriteAttributeString ( "prerelease" ,  "true" ) ; 
192+                                     if  ( configuration . IgnoreDependencies )  xw . WriteAttributeString ( "ignoreDependencies" ,  "true" ) ; 
193+                                     if  ( configuration . ForceX86 )  xw . WriteAttributeString ( "forceX86" ,  "true" ) ; 
194+ 
195+                                     if  ( ! string . IsNullOrWhiteSpace ( configuration . InstallArguments ) )  xw . WriteAttributeString ( "installArguments" ,  configuration . InstallArguments ) ; 
196+                                     if  ( configuration . OverrideArguments )  xw . WriteAttributeString ( "overrideArguments" ,  "true" ) ; 
197+                                     if  ( configuration . ApplyInstallArgumentsToDependencies )  xw . WriteAttributeString ( "applyInstallArgumentsToDependencies" ,  "true" ) ; 
198+ 
199+                                     if  ( ! string . IsNullOrWhiteSpace ( configuration . PackageParameters ) )  xw . WriteAttributeString ( "packageParameters" ,  configuration . PackageParameters ) ; 
200+                                     if  ( configuration . ApplyPackageParametersToDependencies )  xw . WriteAttributeString ( "applyPackageParametersToDependencies" ,  "true" ) ; 
201+ 
202+                                     if  ( configuration . AllowDowngrade )  xw . WriteAttributeString ( "allowDowngrade" ,  "true" ) ; 
203+                                     if  ( configuration . AllowMultipleVersions )  xw . WriteAttributeString ( "allowMultipleVersions" ,  "true" ) ; 
204+ 
205+                                     if  ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Username ) )  xw . WriteAttributeString ( "user" ,  configuration . SourceCommand . Username ) ; 
206+                                     if  ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Password ) )  xw . WriteAttributeString ( "password" ,  configuration . SourceCommand . Password ) ; 
207+                                     if  ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Certificate ) )  xw . WriteAttributeString ( "cert" ,  configuration . SourceCommand . Certificate ) ; 
208+                                     if  ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . CertificatePassword ) )  xw . WriteAttributeString ( "certPassword" ,  configuration . SourceCommand . CertificatePassword ) ; 
209+ 
210+                                     //Arguments from the global options set 
211+                                     if  ( configuration . CommandExecutionTimeoutSeconds  !=  ApplicationParameters . DefaultWaitForExitInSeconds ) 
212+                                     { 
213+                                         xw . WriteAttributeString ( "timeout" , configuration . CommandExecutionTimeoutSeconds . to_string ( ) ) ; 
214+                                     } 
215+ 
216+                                     //TODO, should this be exported? It seems rather system specific 
217+                                     //if (!string.IsNullOrWhiteSpace(configuration.CacheLocation)) xw.WriteAttributeString("cacheLocation", configuration.CacheLocation); 
218+ 
219+                                     if  ( configuration . Features . FailOnStandardError )  xw . WriteAttributeString ( "failOnStderr" ,  "true" ) ; 
220+                                     if  ( ! configuration . Features . UsePowerShellHost )  xw . WriteAttributeString ( "useSystemPowershell" ,  "true" ) ; 
221+ 
222+                                     //Make sure to reset the configuration 
223+                                     configuration  =  originalConfiguration . deep_copy ( ) ; 
224+                                 } 
225+ 
164226                                xw . WriteEndElement ( ) ; 
165227                            } 
166228
0 commit comments