@@ -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 configure_argument_parser ( OptionSet optionSet , ChocolateyConfiguration configuration )
@@ -53,6 +61,9 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati
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 1.2.0+" ,
66
+ option => configuration . ExportCommand . IncludeRememberedPackageArguments = option != null )
56
67
;
57
68
}
58
69
@@ -98,12 +109,14 @@ choco export [<options/switches>]
98
109
"chocolatey" . Log ( ) . Info ( @"
99
110
choco export
100
111
choco export --include-version-numbers
112
+ choco export --include-version-numbers --include-remembered-arguments
101
113
choco export ""'c:\temp\packages.config'""
102
114
choco export ""'c:\temp\packages.config'"" --include-version-numbers
103
115
choco export -o=""'c:\temp\packages.config'""
104
116
choco export -o=""'c:\temp\packages.config'"" --include-version-numbers
105
117
choco export --output-file-path=""'c:\temp\packages.config'""
106
118
choco export --output-file-path=""'c:\temp\packages.config'"" --include-version-numbers
119
+ choco export --output-file-path=""'c:\temp\packages.config'"" --include-remembered-arguments
107
120
108
121
NOTE: See scripting in the command reference (`choco -?`) for how to
109
122
write proper scripts and integrations.
@@ -134,14 +147,26 @@ public bool may_require_admin_access()
134
147
135
148
public void noop ( ChocolateyConfiguration configuration )
136
149
{
137
- 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 ) ) ;
150
+ 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 ) ) ;
138
151
}
139
152
140
153
public void run ( ChocolateyConfiguration configuration )
141
154
{
142
155
var installedPackages = _nugetService . get_all_installed_packages ( configuration ) ;
143
156
var xmlWriterSettings = new XmlWriterSettings { Indent = true , Encoding = new UTF8Encoding ( false ) } ;
144
157
158
+ // Add the options set from the install command.
159
+ ConfigurationOptions . OptionSet . Remove ( "o" ) ;
160
+ var installCommand = new ChocolateyInstallCommand ( _packageService ) ;
161
+ // If the --source option is available, assume that the install command arguments have already been added.
162
+ // This is required for when this method multiple times in a row, such as in the unit tests.
163
+ if ( ! ConfigurationOptions . OptionSet . Contains ( "source" ) )
164
+ {
165
+ installCommand . configure_argument_parser ( ConfigurationOptions . OptionSet , configuration ) ;
166
+ }
167
+ // Make sure we have a clean configuration to revert to after parsing remembered arguments.
168
+ configuration . start_backup ( ) ;
169
+
145
170
FaultTolerance . try_catch_with_logging_exception (
146
171
( ) =>
147
172
{
@@ -164,6 +189,50 @@ public void run(ChocolateyConfiguration configuration)
164
189
packageElement . Version = packageResult . Package . Version . ToString ( ) ;
165
190
}
166
191
192
+ if ( configuration . ExportCommand . IncludeRememberedPackageArguments )
193
+ {
194
+
195
+ var pkgInfo = _packageInfoService . get_package_information ( packageResult . Package ) ;
196
+ configuration . Features . UseRememberedArgumentsForUpgrades = true ;
197
+ _nugetService . set_package_config_for_upgrade ( configuration , pkgInfo ) ;
198
+
199
+ // Mirrors the arguments captured in ChocolateyPackageService.capture_arguments()
200
+
201
+ if ( configuration . Prerelease ) packageElement . Prerelease = true ;
202
+ if ( configuration . IgnoreDependencies ) packageElement . IgnoreDependencies = true ;
203
+ if ( configuration . ForceX86 ) packageElement . ForceX86 = true ;
204
+
205
+ if ( ! string . IsNullOrWhiteSpace ( configuration . InstallArguments ) ) packageElement . InstallArguments = configuration . InstallArguments ;
206
+ if ( configuration . OverrideArguments ) packageElement . OverrideArguments = true ;
207
+ if ( configuration . ApplyInstallArgumentsToDependencies ) packageElement . ApplyInstallArgumentsToDependencies = true ;
208
+
209
+ if ( ! string . IsNullOrWhiteSpace ( configuration . PackageParameters ) ) packageElement . PackageParameters = configuration . PackageParameters ;
210
+ if ( configuration . ApplyPackageParametersToDependencies ) packageElement . ApplyPackageParametersToDependencies = true ;
211
+
212
+ if ( configuration . AllowDowngrade ) packageElement . AllowDowngrade = true ;
213
+ if ( configuration . AllowMultipleVersions ) packageElement . AllowMultipleVersions = true ;
214
+
215
+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Username ) ) packageElement . User = configuration . SourceCommand . Username ;
216
+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Password ) ) packageElement . Password = configuration . SourceCommand . Password ;
217
+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . Certificate ) ) packageElement . Cert = configuration . SourceCommand . Certificate ;
218
+ if ( ! string . IsNullOrWhiteSpace ( configuration . SourceCommand . CertificatePassword ) ) packageElement . CertPassword = configuration . SourceCommand . CertificatePassword ;
219
+
220
+ // Arguments from the global options set
221
+ if ( configuration . CommandExecutionTimeoutSeconds != ApplicationParameters . DefaultWaitForExitInSeconds )
222
+ {
223
+ packageElement . ExecutionTimeout = configuration . CommandExecutionTimeoutSeconds ;
224
+ }
225
+
226
+ // This was discussed in the PR, and because it is potentially system specific, it should not be included in the exported file
227
+ // if (!string.IsNullOrWhiteSpace(configuration.CacheLocation)) packageElement.CacheLocation = configuration.CacheLocation;
228
+
229
+ // if (configuration.Features.FailOnStandardError) packageElement.FailOnStderr = true;
230
+ // if (!configuration.Features.UsePowerShellHost) packageElement.UseSystemPowershell = true;
231
+
232
+ // Make sure to reset the configuration so as to be able to parse the next set of remembered arguments
233
+ configuration . reset_config ( ) ;
234
+ }
235
+
167
236
packagesConfig . Packages . Add ( packageElement ) ;
168
237
}
169
238
0 commit comments