Skip to content

Commit 31f37fc

Browse files
authored
Merge pull request #19 from gui-cs/copilot/add-short-aliases-for-options
Add short aliases for CLI options (-j, -f, -i, -t)
2 parents 706f58e + 8fbe36c commit 31f37fc

3 files changed

Lines changed: 43 additions & 10 deletions

File tree

src/Clet/Help/overview.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
| Option | Description |
1414
|--------|-------------|
15-
| `--initial <value>` | Pre-populate the input with a value |
16-
| `--title <text>` | Custom title for the prompt window |
17-
| `--json` | Emit result as a JSON envelope |
18-
| `--timeout <duration>` | Auto-cancel after duration (e.g. `30s`, `1m`, `500ms`) |
19-
| `--fullscreen` | Force fullscreen rendering (default for viewers) |
15+
| `--initial`, `-i` `<value>` | Pre-populate the input with a value |
16+
| `--title`, `-t` `<text>` | Custom title for the prompt window |
17+
| `--json`, `-j` | Emit result as a JSON envelope |
18+
| `--timeout` `<duration>` | Auto-cancel after duration (e.g. `30s`, `1m`, `500ms`) |
19+
| `--fullscreen`, `-f` | Force fullscreen rendering (default for viewers) |
2020

2121
## JSON Output
2222

src/Clet/Hosting/CommandLineRoot.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ private async Task<int> DispatchAlias (
7171
{
7272
string arg = args [i];
7373

74-
if (arg == "--json")
74+
if (arg is "--json" or "-j")
7575
{
7676
jsonOutput = true;
7777

7878
continue;
7979
}
8080

81-
if (arg == "--fullscreen")
81+
if (arg is "--fullscreen" or "-f")
8282
{
8383
fullscreen = true;
8484

@@ -106,7 +106,7 @@ private async Task<int> DispatchAlias (
106106
continue;
107107
}
108108

109-
if (arg == "--initial")
109+
if (arg is "--initial" or "-i")
110110
{
111111
if (i + 1 >= args.Length)
112112
{
@@ -120,7 +120,7 @@ private async Task<int> DispatchAlias (
120120
continue;
121121
}
122122

123-
if (arg == "--title")
123+
if (arg is "--title" or "-t")
124124
{
125125
if (i + 1 >= args.Length)
126126
{
@@ -190,7 +190,7 @@ private int WriteAliasHelp (string[] args, TextWriter stdout, TextWriter stderr)
190190

191191
private int WriteList (string[] args, TextWriter stdout)
192192
{
193-
bool json = args.Length > 1 && args [1] == "--json";
193+
bool json = args.Length > 1 && args [1] is "--json" or "-j";
194194

195195
if (json)
196196
{

tests/Clet.UnitTests/CommandLineRootTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,37 @@ public async Task RootHelp_MentionsTitleFlag ()
171171
Assert.Equal (ExitCodes.Ok, exit);
172172
Assert.Contains ("--title", stdout.ToString ());
173173
}
174+
175+
[Fact]
176+
public async Task List_ShortJsonFlag_EmitsJson ()
177+
{
178+
(CommandLineRoot root, StringWriter stdout, StringWriter stderr) = Build ();
179+
180+
int exit = await root.InvokeAsync (["list", "-j"], CancellationToken.None, stdout, stderr);
181+
182+
Assert.Equal (ExitCodes.Ok, exit);
183+
Assert.Contains ("\"schemaVersion\":1", stdout.ToString ());
184+
}
185+
186+
[Fact]
187+
public async Task Alias_ShortTitleFlag_MissingValue_ExitsWithUsageError ()
188+
{
189+
(CommandLineRoot root, StringWriter stdout, StringWriter stderr) = Build ();
190+
191+
int exit = await root.InvokeAsync (["select", "-t"], CancellationToken.None, stdout, stderr);
192+
193+
Assert.Equal (ExitCodes.UsageError, exit);
194+
Assert.Contains ("--title", stderr.ToString ());
195+
}
196+
197+
[Fact]
198+
public async Task Alias_ShortInitialFlag_MissingValue_ExitsWithUsageError ()
199+
{
200+
(CommandLineRoot root, StringWriter stdout, StringWriter stderr) = Build ();
201+
202+
int exit = await root.InvokeAsync (["select", "-i"], CancellationToken.None, stdout, stderr);
203+
204+
Assert.Equal (ExitCodes.UsageError, exit);
205+
Assert.Contains ("--initial", stderr.ToString ());
206+
}
174207
}

0 commit comments

Comments
 (0)