Skip to content

Commit 042fccb

Browse files
committed
Added -help option so sourcekitd-test
Added "-help" option to Options.td Added also: * Added "OPT_HELP" case in the main TestOptions.cpp switch. It uses the llvm options help functionality to provide up-to-date help * Additional "Use -help for assistance" at the end of the error message that appears when calling an unknown option Added their following tests, respectively:: * usage.swift, and * wrong_arguments.swift Extra: FIXME: in TestOptions::printHelp, suggesting a possible expansion for the printHelp option (details in file)
1 parent 763b573 commit 042fccb

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

test/SourceKit/Misc/usage.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Sanity check that -help works
2+
3+
// RUN: not %sourcekitd-test -help | %FileCheck %s
4+
5+
// CHECK: USAGE: sourcekitd-test [options] <inputs>
6+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Check that from invalid input, program suggests using -help
2+
3+
// RUN: not %sourcekitd-test -this_option_does_not_exist 2>&1 | %FileCheck %s
4+
5+
// CHECK: error: unknown argument: -this_option_does_not_exist
6+
// CHECK: Use -h or -help for assistance
7+

tools/SourceKit/tools/sourcekitd-test/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@ def objc_name : Separate<["-"], "objc-name">,
102102

103103
def objc_selector : Separate<["-"], "objc-selector">,
104104
HelpText<"Objective-C selector name to translate from">;
105+
106+
def help : Flag<["-", "--"], "help">,
107+
HelpText<"Display available options">;
108+
109+
def h : Flag<["-"], "h">, Alias<help>;

tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ bool TestOptions::parseArgs(llvm::ArrayRef<const char *> Args) {
146146
}
147147
break;
148148

149+
case OPT_help: {
150+
printHelp(false);
151+
return true;
152+
break;
153+
}
154+
149155
case OPT_offset:
150156
if (StringRef(InputArg->getValue()).getAsInteger(10, Offset)) {
151157
llvm::errs() << "error: expected integer for 'offset'\n";
@@ -279,7 +285,8 @@ bool TestOptions::parseArgs(llvm::ArrayRef<const char *> Args) {
279285

280286
case OPT_UNKNOWN:
281287
llvm::errs() << "error: unknown argument: "
282-
<< InputArg->getAsString(ParsedArgs) << '\n';
288+
<< InputArg->getAsString(ParsedArgs) << '\n'
289+
<< "Use -h or -help for assistance" << '\n';
283290
return true;
284291
}
285292
}
@@ -292,3 +299,16 @@ bool TestOptions::parseArgs(llvm::ArrayRef<const char *> Args) {
292299

293300
return false;
294301
}
302+
303+
void TestOptions::printHelp(bool ShowHidden) const {
304+
305+
// Based off of swift/lib/Driver/Driver.cpp, at Driver::printHelp
306+
//FIXME: should we use IncludedFlagsBitmask and ExcludedFlagsBitmask?
307+
// Maybe not for modes such as Interactive, Batch, AutolinkExtract, etc,
308+
// as in Driver.cpp. But could be useful for extra info, like HelpHidden.
309+
310+
TestOptTable Table;
311+
312+
Table.PrintHelp(llvm::outs(), "sourcekitd-test", "SourceKit Testing Tool",
313+
ShowHidden);
314+
}

tools/SourceKit/tools/sourcekitd-test/TestOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct TestOptions {
9090
bool CollectActionables = false;
9191
bool isAsyncRequest = false;
9292
bool parseArgs(llvm::ArrayRef<const char *> Args);
93+
void printHelp(bool ShowHidden) const;
9394
};
9495

9596
}

0 commit comments

Comments
 (0)