Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Commit 6bea801

Browse files
author
Immo Landwerth
committed
Remove support for slash options
Supporting slashes seems problematic for cross-platform usage. When running on non-Windows platform, we'd have to disallow it anyways in order to avoid parsing issues. On Windows there is already enough prior-art to justify dropping support for it. For instance, PowerShell doesn't slashes either. Also, Windows users have started to use many ports of Unix tools, such as Git, that also don't support slashes. The only downside of removing support for slashes is that existing tools that support slashes can't start to depend on this library. Until we've anybody asking for it, it seems better to start clean.
1 parent d04d844 commit 6bea801

File tree

4 files changed

+22
-42
lines changed

4 files changed

+22
-42
lines changed

src/System.CommandLine/README.md

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -101,44 +101,29 @@ They can be *bundled* together, such as
101101

102102
$ tool -xdf
103103

104-
You can also use a slash, e.g.
105-
106-
$ tool /x /d /f
107-
108-
However, slashes don't support bundling. For example, the following isn't
109-
recognized:
110-
111-
# This is not equivalent to -xdf
112-
$ tool /xdf
104+
Please note that slashes aren't supported.
113105

114106
### Keyword options
115107

116108
Keyword options are delimited by two dashes, such as:
117109

118110
$ tool --verbose
119111

120-
Alternatively, you can use a slash:
121-
122-
$ tool /verbose
123-
124-
Using two dashes avoids any ambiguity with bundled forms -- which is why
125-
slashes don't support bundling.
126-
127112
### Option arguments
128113

129114
Both, the single letter form, as well as the long forms, support arguments.
130115
Arguments must be separated by either a space, an equal sign or a colon:
131116

132117
# All three forms are identical:
133-
$ tool /out result.exe
134-
$ tool /out=result.exe
135-
$ tool /out:result.exe
118+
$ tool --out result.exe
119+
$ tool --out=result.exe
120+
$ tool --out:result.exe
136121

137122
Multiple spaces are allowed as well:
138123

139-
$ tool /out result.exe
140-
$ tool /out = result.exe
141-
$ tool /out : result.exe
124+
$ tool --out result.exe
125+
$ tool --out = result.exe
126+
$ tool --out : result.exe
142127

143128
This even works when combined with bundling, but in that case only the last
144129
option can have an argument. So this:
@@ -278,7 +263,7 @@ will be an argument or the first parameter.
278263
Both, options and parameters, support the notion of lists. For example, consider
279264
the C# compiler CSC:
280265

281-
$ csc /r:mscorlib.dll /r:system.dll source1.cs source2.cs /out:hello.exe /t:exe
266+
$ csc -r:mscorlib.dll -r:system.dll source1.cs source2.cs -out:hello.exe -t:exe
282267

283268
You would define the options and parameters as follows:
284269

src/System.CommandLine/src/System/CommandLine/ArgumentLexer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ private static void ExpandOptionBundle(IList<ArgumentToken> receiver, int index)
160160
private static bool TryExtractOption(string text, out string modifier, out string remainder)
161161
{
162162
return TryExtractOption(text, @"--", out modifier, out remainder) ||
163-
TryExtractOption(text, @"-", out modifier, out remainder) ||
164-
TryExtractOption(text, @"/", out modifier, out remainder);
163+
TryExtractOption(text, @"-", out modifier, out remainder);
165164
}
166165

167166
private static bool TryExtractOption(string text, string prefix, out string modifier, out string remainder)

src/System.CommandLine/tests/System/CommandLine/Tests/ArgumentLexerTests.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ public void Lex_Parameters()
2727
[Fact]
2828
public void Lex_Options()
2929
{
30-
var text = "-a /b --c";
30+
var text = "-a --b";
3131
var actual = Lex(text);
3232
var expected = new[] {
3333
new ArgumentToken("-", "a", null),
34-
new ArgumentToken("/", "b", null),
35-
new ArgumentToken("--", "c", null)
34+
new ArgumentToken("--", "b", null)
3635
};
3736

3837
Assert.Equal(expected, actual);
@@ -41,11 +40,11 @@ public void Lex_Options()
4140
[Fact]
4241
public void Lex_OptionArguments()
4342
{
44-
var text = "-a:va /b=vb --c vc";
43+
var text = "-a:va -b=vb --c vc";
4544
var actual = Lex(text);
4645
var expected = new[] {
4746
new ArgumentToken("-", "a", "va"),
48-
new ArgumentToken("/", "b", "vb"),
47+
new ArgumentToken("-", "b", "vb"),
4948
new ArgumentToken("--", "c", null),
5049
new ArgumentToken(null, "vc", null)
5150
};
@@ -68,12 +67,12 @@ public void Lex_ExpandsBundles()
6867
}
6968

7069
[Fact]
71-
public void Lex_ExpandsBundles_UnlessUsingSlash()
70+
public void Lex_ExpandsBundles_UnlessUsingDashDash()
7271
{
73-
var text = "/xdf";
72+
var text = "--xdf";
7473
var actual = Lex(text);
7574
var expected = new[] {
76-
new ArgumentToken("/", "xdf", null)
75+
new ArgumentToken("--", "xdf", null)
7776
};
7877

7978
Assert.Equal(expected, actual);
@@ -87,7 +86,7 @@ public void Lex_ExpandsReponseFile()
8786
{
8887
"-xdf",
8988
"--out:out.exe",
90-
"/responseFileReader",
89+
"--responseFileReader",
9190
@"C:\Reference Assemblies\system.dll"
9291
};
9392

@@ -100,7 +99,7 @@ public void Lex_ExpandsReponseFile()
10099
new ArgumentToken("-", "d", null),
101100
new ArgumentToken("-", "f", null),
102101
new ArgumentToken("--", "out", "out.exe"),
103-
new ArgumentToken("/", "responseFileReader", null),
102+
new ArgumentToken("--", "responseFileReader", null),
104103
new ArgumentToken(null, @"C:\Reference Assemblies\system.dll", null),
105104
new ArgumentToken("--", "after", null)
106105
};

src/System.CommandLine/tests/System/CommandLine/Tests/ArgumentSyntaxTests.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,22 +466,20 @@ public void Option_Usage_Error_RequiresValue(string commandLine)
466466
Assert.Equal("option -a requires a value", ex.Message);
467467
}
468468

469-
[Theory]
470-
[InlineData("/")]
471-
[InlineData("--")]
472-
public void Option_Usage_Error_Flag_Bundle_ViaModifier(string modifier)
469+
[Fact]
470+
public void Option_Usage_Error_Flag_Bundle_ViaDashDash()
473471
{
474472
var ex = Assert.Throws<ArgumentSyntaxException>(() =>
475473
{
476-
Parse(modifier + "opq", syntax =>
474+
Parse("--opq", syntax =>
477475
{
478476
syntax.DefineOption("o", false);
479477
syntax.DefineOption("p", false);
480478
syntax.DefineOption("q", false);
481479
});
482480
});
483481

484-
Assert.Equal("invalid option " + modifier + "opq", ex.Message);
482+
Assert.Equal("invalid option --opq", ex.Message);
485483
}
486484

487485
[Theory]
@@ -499,7 +497,6 @@ public void Option_Usage_ViaNonLetterName(string name)
499497
}
500498

501499
[Theory]
502-
[InlineData("/")]
503500
[InlineData("-")]
504501
[InlineData("--")]
505502
public void Option_Usage_ViaModifer(string modifier)

0 commit comments

Comments
 (0)