@@ -46,14 +46,22 @@ public class ChocolateyExportCommand : ICommand
46
46
private readonly IContainerResolver _containerResolver ;
47
47
private readonly IRegistryService _registryService ;
48
48
private readonly IChocolateyPackageInformationService _packageInfoService ;
49
-
50
- public ChocolateyExportCommand ( INugetService nugetService , IFileSystem fileSystem , IContainerResolver containerResolver , IRegistryService registryService , IChocolateyPackageInformationService packageInfoService )
49
+ private readonly IChocolateyPackageService _packageService ;
50
+
51
+ public ChocolateyExportCommand (
52
+ INugetService nugetService ,
53
+ IFileSystem fileSystem ,
54
+ IContainerResolver containerResolver ,
55
+ IRegistryService registryService ,
56
+ IChocolateyPackageInformationService packageInfoService ,
57
+ IChocolateyPackageService packageService )
51
58
{
52
59
_nugetService = nugetService ;
53
60
_fileSystem = fileSystem ;
54
61
_containerResolver = containerResolver ;
55
62
_registryService = registryService ;
56
63
_packageInfoService = packageInfoService ;
64
+ _packageService = packageService ;
57
65
}
58
66
59
67
public void ConfigureArgumentParser ( OptionSet optionSet , ChocolateyConfiguration configuration )
@@ -71,6 +79,9 @@ public void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfiguration
71
79
. Add ( "include-alternative-sources" ,
72
80
"IncludeAlternativeSources - Includes software from alternative sources which are managed by Chocolatey CLI." ,
73
81
option => configuration . ExportCommand . IncludeAlternativeSources = option != null )
82
+ . Add ( "include-arguments|include-remembered-arguments" ,
83
+ "Include Remembered Arguments - controls whether or not remembered arguments for each package appear in generated file. Defaults to false. Available in 2.3.0+" ,
84
+ option => configuration . ExportCommand . IncludeRememberedPackageArguments = option != null )
74
85
;
75
86
}
76
87
@@ -114,12 +125,14 @@ choco export [<options/switches>]
114
125
"chocolatey" . Log ( ) . Info ( @"
115
126
choco export
116
127
choco export --include-version-numbers
128
+ choco export --include-version-numbers --include-remembered-arguments
117
129
choco export ""'c:\temp\packages.config'""
118
130
choco export ""'c:\temp\packages.config'"" --include-version-numbers
119
131
choco export -o=""'c:\temp\packages.config'""
120
132
choco export -o=""'c:\temp\packages.config'"" --include-version-numbers
121
133
choco export --output-file-path=""'c:\temp\packages.config'""
122
134
choco export --output-file-path=""'c:\temp\packages.config'"" --include-version-numbers
135
+ choco export --output-file-path=""""'c:\temp\packages.config'"""" --include-remembered-arguments
123
136
124
137
NOTE: See scripting in the command reference (`choco -?`) for how to
125
138
write proper scripts and integrations.
@@ -150,14 +163,16 @@ public bool MayRequireAdminAccess()
150
163
151
164
public void DryRun ( ChocolateyConfiguration configuration )
152
165
{
153
- 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 ) ) ;
166
+ 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 ) ) ;
154
167
}
155
168
156
169
public void Run ( ChocolateyConfiguration configuration )
157
170
{
158
171
var installedPackages = _nugetService . GetInstalledPackages ( configuration ) ;
159
172
var xmlWriterSettings = new XmlWriterSettings { Indent = true , Encoding = new UTF8Encoding ( false ) } ;
160
173
174
+ configuration . CreateBackup ( ) ;
175
+
161
176
FaultTolerance . TryCatchWithLoggingException (
162
177
( ) =>
163
178
{
@@ -182,6 +197,93 @@ public void Run(ChocolateyConfiguration configuration)
182
197
183
198
xw . WriteAttributeString ( "sourceType" , "nuget" ) ;
184
199
200
+ if ( configuration . ExportCommand . IncludeRememberedPackageArguments )
201
+ {
202
+ var pkgInfo = _packageInfoService . Get ( packageResult . PackageMetadata ) ;
203
+ configuration . Features . UseRememberedArgumentsForUpgrades = true ;
204
+ var rememberedConfig = _nugetService . GetPackageConfigFromRememberedArguments ( configuration , pkgInfo ) ;
205
+
206
+ // Mirrors the arguments captured in ChocolateyPackageService.CaptureArguments()
207
+ if ( configuration . Prerelease )
208
+ {
209
+ packageElement . Prerelease = true ;
210
+ }
211
+
212
+ if ( configuration . IgnoreDependencies )
213
+ {
214
+ packageElement . IgnoreDependencies = true ;
215
+ }
216
+
217
+ if ( configuration . ForceX86 )
218
+ {
219
+ packageElement . ForceX86 = true ;
220
+ }
221
+
222
+ if ( ! string . IsNullOrWhiteSpace ( configuration . InstallArguments ) )
223
+ {
224
+ packageElement . InstallArguments = configuration . InstallArguments ;
225
+ }
226
+
227
+ if ( configuration . OverrideArguments )
228
+ {
229
+ packageElement . OverrideArguments = true ;
230
+ }
231
+
232
+ if ( configuration . ApplyInstallArgumentsToDependencies )
233
+ {
234
+ packageElement . ApplyInstallArgumentsToDependencies = true ;
235
+ }
236
+
237
+ if ( ! string . IsNullOrWhiteSpace ( configuration . PackageParameters ) )
238
+ {
239
+ packageElement . PackageParameters = configuration . PackageParameters ;
240
+ }
241
+
242
+ if ( configuration . ApplyPackageParametersToDependencies )
243
+ {
244
+ packageElement . ApplyPackageParametersToDependencies = true ;
245
+ }
246
+
247
+ if ( configuration . AllowDowngrade )
248
+ {
249
+ packageElement . AllowDowngrade = true ;
250
+ }
251
+
252
+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Username ) )
253
+ {
254
+ packageElement . User = configuration . SourceCommand . Username ;
255
+ }
256
+
257
+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Password ) )
258
+ {
259
+ packageElement . Password = configuration . SourceCommand . Password ;
260
+ }
261
+
262
+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Certificate ) )
263
+ {
264
+ packageElement . Cert = configuration . SourceCommand . Certificate ;
265
+ }
266
+
267
+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . CertificatePassword ) )
268
+ {
269
+ packageElement . CertPassword = configuration . SourceCommand . CertificatePassword ;
270
+ }
271
+
272
+ // Arguments from the global options set
273
+ if ( configuration . CommandExecutionTimeoutSeconds != ApplicationParameters . DefaultWaitForExitInSeconds )
274
+ {
275
+ packageElement . ExecutionTimeout = configuration . CommandExecutionTimeoutSeconds ;
276
+ }
277
+
278
+ // This was discussed in the PR, and because it is potentially system specific, it should not be included in the exported file
279
+ // if (!string.IsNullOrWhiteSpace(configuration.CacheLocation)) packageElement.CacheLocation = configuration.CacheLocation;
280
+ // if (configuration.Features.FailOnStandardError) packageElement.FailOnStderr = true;
281
+ // if (!configuration.Features.UsePowerShellHost) packageElement.UseSystemPowershell = true;
282
+
283
+ // Make sure to reset the configuration so as to be able to parse the next set of remembered arguments
284
+ configuration . RevertChanges ( ) ;
285
+ }
286
+
185
287
packagesConfig . Packages . Add ( packageElement ) ;
186
288
}
187
289
0 commit comments