@@ -36,11 +36,14 @@ public class ChocolateyExportCommand : ICommand
36
36
{
37
37
private readonly INugetService _nugetService ;
38
38
private readonly IFileSystem _fileSystem ;
39
+ private readonly IChocolateyPackageInformationService _packageInfoService ;
40
+ private readonly IChocolateyPackageService _packageService ;
39
41
40
- public ChocolateyExportCommand ( INugetService nugetService , IFileSystem fileSystem )
42
+ public ChocolateyExportCommand ( INugetService nugetService , IFileSystem fileSystem , IChocolateyPackageInformationService packageInfoService )
41
43
{
42
44
_nugetService = nugetService ;
43
45
_fileSystem = fileSystem ;
46
+ _packageInfoService = packageInfoService ;
44
47
}
45
48
46
49
public void configure_argument_parser ( OptionSet optionSet , ChocolateyConfiguration configuration )
@@ -52,6 +55,9 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati
52
55
. Add ( "include-version-numbers|include-version" ,
53
56
"Include Version Numbers - controls whether or not version numbers for each package appear in generated file. Defaults to false." ,
54
57
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 )
55
61
;
56
62
}
57
63
@@ -97,12 +103,14 @@ choco export [<options/switches>]
97
103
"chocolatey" . Log ( ) . Info ( @"
98
104
choco export
99
105
choco export --include-version-numbers
106
+ choco export --include-version-numbers --include-remembered-arguments
100
107
choco export ""'c:\temp\packages.config'""
101
108
choco export ""'c:\temp\packages.config'"" --include-version-numbers
102
109
choco export -o=""'c:\temp\packages.config'""
103
110
choco export -o=""'c:\temp\packages.config'"" --include-version-numbers
104
111
choco export --output-file-path=""'c:\temp\packages.config'""
105
112
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
106
114
107
115
NOTE: See scripting in the command reference (`choco -?`) for how to
108
116
write proper scripts and integrations.
@@ -140,6 +148,17 @@ public void run(ChocolateyConfiguration configuration)
140
148
{
141
149
var packageResults = _nugetService . get_all_installed_packages ( configuration ) ;
142
150
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
+ }
143
162
144
163
FaultTolerance . try_catch_with_logging_exception (
145
164
( ) =>
@@ -161,6 +180,49 @@ public void run(ChocolateyConfiguration configuration)
161
180
xw . WriteAttributeString ( "version" , packageResult . Package . Version . ToString ( ) ) ;
162
181
}
163
182
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
+
164
226
xw . WriteEndElement ( ) ;
165
227
}
166
228
0 commit comments