Skip to content

Commit 01bf648

Browse files
Added Enabled to ResponseSubsystem
1 parent 9e001fe commit 01bf648

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/System.CommandLine.Subsystems.Tests/ResponseSubsystemTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public void Simple_response_file_contributes_to_parsing()
1919
var rootCommand = new CliRootCommand { option };
2020
var configuration = new CliConfiguration(rootCommand);
2121
var subsystem = new ResponseSubsystem();
22+
subsystem.Enabled = true;
2223
string[] args = ["@Response_1.rsp"];
2324

2425
Subsystem.Initialize(subsystem, configuration, args);

src/System.CommandLine.Subsystems/Directives/ResponseSubsystem.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,33 @@ namespace System.CommandLine.Directives;
99
public class ResponseSubsystem()
1010
: CliSubsystem("Response", SubsystemKind.Response, null)
1111
{
12+
public bool Enabled { get; set; }
13+
1214
protected internal override void Initialize(InitializationContext context)
1315
=> context.Configuration.ResponseFileTokenReplacer = Replacer;
1416

15-
public static (List<string>? tokens, List<string>? errors) Replacer(string responseSourceName)
17+
public (List<string>? tokens, List<string>? errors) Replacer(string responseSourceName)
1618
{
17-
try
18-
{
19-
// TODO: Include checks from previous system.
20-
var contents = File.ReadAllText(responseSourceName);
21-
return (CliParser.SplitCommandLine(contents).ToList(), null);
22-
}
23-
catch
19+
if (Enabled)
2420
{
25-
// TODO: Switch to proper errors
26-
return (null,
27-
errors:
28-
[
29-
$"Failed to open response file {responseSourceName}"
30-
]);
21+
try
22+
{
23+
// TODO: Include checks from previous system.
24+
var contents = File.ReadAllText(responseSourceName);
25+
return (CliParser.SplitCommandLine(contents).ToList(), null);
26+
}
27+
catch
28+
{
29+
// TODO: Switch to proper errors
30+
return (null,
31+
errors:
32+
[
33+
$"Failed to open response file {responseSourceName}"
34+
]);
35+
}
3136
}
37+
// TODO: Confirm this is not an error state
38+
return ([responseSourceName], null);
3239
}
3340

3441
// TODO: File handling from previous system - ensure these checks are done (note: no tests caught these oversights

0 commit comments

Comments
 (0)