From f8fdf4c61c218bdb1a117375205e911181d8a5b7 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 17 Sep 2019 09:25:52 +0000 Subject: [PATCH] [llvm-ar] Parse 'h' and '-h': display help and exit Support `llvm-ar h` and `llvm-ar -h` because they may be what users try at first. Note, operation 'h' is undocumented in GNU ar. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D67560 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372088 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tools/llvm-ar/help-message.test | 6 ++++++ tools/llvm-ar/llvm-ar.cpp | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 test/tools/llvm-ar/help-message.test diff --git a/test/tools/llvm-ar/help-message.test b/test/tools/llvm-ar/help-message.test new file mode 100644 index 00000000000..ed17667291d --- /dev/null +++ b/test/tools/llvm-ar/help-message.test @@ -0,0 +1,6 @@ +# RUN: llvm-ar h | FileCheck %s +# RUN: llvm-ar -h | FileCheck %s +# RUN: llvm-ar -help | FileCheck %s +# RUN: llvm-ar --help | FileCheck %s + +# CHECK: USAGE: llvm-ar diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 9447298421b..006d8ed74cf 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -70,14 +70,14 @@ USAGE: llvm-ar [options] [-][modifiers] [relpos] [count] [f llvm-ar -M [ - Ignored for compatibility - --help - Display available options - --version - Display the version of this program + --plugin= - ignored for compatibility + -h --help - display this help and exit + --version - print the version and exit @ - read options from OPERATIONS: @@ -1030,7 +1030,7 @@ static void runMRIScript() { } static bool handleGenericOption(StringRef arg) { - if (arg == "-help" || arg == "--help") { + if (arg == "h" || arg.startswith("-h") || arg == "--help") { printHelpMessage(); return true; } -- 2.11.4.GIT