Skip to content

Added -help option to sourcekitd-test #8746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/SourceKit/Misc/usage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Sanity check that -help works

// RUN: not %sourcekitd-test -help | %FileCheck %s

// CHECK: USAGE: sourcekitd-test [options] <inputs>

7 changes: 7 additions & 0 deletions test/SourceKit/Misc/wrong_arguments.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Check that from invalid input, program suggests using -help

// RUN: not %sourcekitd-test -this_option_does_not_exist 2>&1 | %FileCheck %s

// CHECK: error: unknown argument: -this_option_does_not_exist
// CHECK: Use -h or -help for assistance

5 changes: 5 additions & 0 deletions tools/SourceKit/tools/sourcekitd-test/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,8 @@ def objc_name : Separate<["-"], "objc-name">,

def objc_selector : Separate<["-"], "objc-selector">,
HelpText<"Objective-C selector name to translate from">;

def help : Flag<["-", "--"], "help">,
HelpText<"Display available options">;

def h : Flag<["-"], "h">, Alias<help>;
22 changes: 21 additions & 1 deletion tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ bool TestOptions::parseArgs(llvm::ArrayRef<const char *> Args) {
}
break;

case OPT_help: {
printHelp(false);
return true;
break;
}

case OPT_offset:
if (StringRef(InputArg->getValue()).getAsInteger(10, Offset)) {
llvm::errs() << "error: expected integer for 'offset'\n";
Expand Down Expand Up @@ -279,7 +285,8 @@ bool TestOptions::parseArgs(llvm::ArrayRef<const char *> Args) {

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

return false;
}

void TestOptions::printHelp(bool ShowHidden) const {

// Based off of swift/lib/Driver/Driver.cpp, at Driver::printHelp
//FIXME: should we use IncludedFlagsBitmask and ExcludedFlagsBitmask?
// Maybe not for modes such as Interactive, Batch, AutolinkExtract, etc,
// as in Driver.cpp. But could be useful for extra info, like HelpHidden.

TestOptTable Table;

Table.PrintHelp(llvm::outs(), "sourcekitd-test", "SourceKit Testing Tool",
ShowHidden);
}
1 change: 1 addition & 0 deletions tools/SourceKit/tools/sourcekitd-test/TestOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct TestOptions {
bool CollectActionables = false;
bool isAsyncRequest = false;
bool parseArgs(llvm::ArrayRef<const char *> Args);
void printHelp(bool ShowHidden) const;
};

}
Expand Down