@@ -37,11 +37,19 @@ public class ChocolateyExportCommand : ICommand
37
37
{
38
38
private readonly INugetService _nugetService ;
39
39
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 )
42
48
{
43
49
_nugetService = nugetService ;
44
50
_fileSystem = fileSystem ;
51
+ _packageInfoService = packageInfoService ;
52
+ _packageService = packageService ;
45
53
}
46
54
47
55
public void ConfigureArgumentParser ( OptionSet optionSet , ChocolateyConfiguration configuration )
@@ -53,6 +61,9 @@ public void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfiguration
53
61
. Add ( "include-version-numbers|include-version" ,
54
62
"Include Version Numbers - controls whether or not version numbers for each package appear in generated file. Defaults to false." ,
55
63
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 )
56
67
;
57
68
}
58
69
@@ -96,12 +107,14 @@ choco export [<options/switches>]
96
107
"chocolatey" . Log ( ) . Info ( @"
97
108
choco export
98
109
choco export --include-version-numbers
110
+ choco export --include-version-numbers --include-remembered-arguments
99
111
choco export ""'c:\temp\packages.config'""
100
112
choco export ""'c:\temp\packages.config'"" --include-version-numbers
101
113
choco export -o=""'c:\temp\packages.config'""
102
114
choco export -o=""'c:\temp\packages.config'"" --include-version-numbers
103
115
choco export --output-file-path=""'c:\temp\packages.config'""
104
116
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
105
118
106
119
NOTE: See scripting in the command reference (`choco -?`) for how to
107
120
write proper scripts and integrations.
@@ -132,14 +145,16 @@ public bool MayRequireAdminAccess()
132
145
133
146
public void DryRun ( ChocolateyConfiguration configuration )
134
147
{
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 ) ) ;
136
149
}
137
150
138
151
public void Run ( ChocolateyConfiguration configuration )
139
152
{
140
153
var installedPackages = _nugetService . GetInstalledPackages ( configuration ) ;
141
154
var xmlWriterSettings = new XmlWriterSettings { Indent = true , Encoding = new UTF8Encoding ( false ) } ;
142
155
156
+ configuration . CreateBackup ( ) ;
157
+
143
158
FaultTolerance . TryCatchWithLoggingException (
144
159
( ) =>
145
160
{
@@ -162,6 +177,40 @@ public void Run(ChocolateyConfiguration configuration)
162
177
packageElement . Version = packageResult . PackageMetadata . Version . ToString ( ) ;
163
178
}
164
179
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
+
165
214
packagesConfig . Packages . Add ( packageElement ) ;
166
215
}
167
216
0 commit comments