diff --git a/llvm/test/tools/llvm-objcopy/ELF/help-message.test b/llvm/test/tools/llvm-objcopy/ELF/help-message.test --- a/llvm/test/tools/llvm-objcopy/ELF/help-message.test +++ b/llvm/test/tools/llvm-objcopy/ELF/help-message.test @@ -1,23 +1,22 @@ -# RUN: llvm-objcopy -h | FileCheck --check-prefix=OBJCOPY-USAGE %s -# RUN: llvm-objcopy --help | FileCheck --check-prefix=OBJCOPY-USAGE %s -# RUN: not llvm-objcopy 2>&1 | FileCheck --check-prefix=OBJCOPY-USAGE %s +# RUN: llvm-objcopy -h | FileCheck --check-prefix=OBJCOPY-USAGE %s --match-full-lines +# RUN: llvm-objcopy --help | FileCheck --check-prefix=OBJCOPY-USAGE %s --match-full-lines +# RUN: not llvm-objcopy 2>&1 | FileCheck --check-prefix=OBJCOPY-USAGE %s --match-full-lines # RUN: not llvm-objcopy -abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s # RUN: not llvm-objcopy --abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s # RUN: not llvm-objcopy --strip-debug 2>&1 | FileCheck %s --check-prefix=NO-INPUT-FILES -# RUN: llvm-strip -h | FileCheck --check-prefix=STRIP-USAGE %s -# RUN: llvm-strip --help | FileCheck --check-prefix=STRIP-USAGE %s -# RUN: not llvm-strip 2>&1 | FileCheck --check-prefix=STRIP-USAGE %s +# RUN: llvm-strip -h | FileCheck --check-prefix=STRIP-USAGE %s --match-full-lines +# RUN: llvm-strip --help | FileCheck --check-prefix=STRIP-USAGE %s --match-full-lines +# RUN: not llvm-strip 2>&1 | FileCheck --check-prefix=STRIP-USAGE %s --match-full-lines # RUN: not llvm-strip -abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s # RUN: not llvm-strip --abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s # RUN: not llvm-strip --strip-debug 2>&1 | FileCheck %s --check-prefix=NO-INPUT-FILES +# OBJCOPY-USAGE: USAGE: llvm-objcopy [options] input [output] +# OBJCOPY-USAGE: Pass @FILE as argument to read options from FILE. -# OBJCOPY-USAGE: USAGE: llvm-objcopy -# OBJCOPY-USAGE: @FILE - -# STRIP-USAGE: USAGE: llvm-strip -# STRIP-USAGE: @FILE +# STRIP-USAGE: USAGE: llvm-strip [options] inputs... +# STRIP-USAGE: Pass @FILE as argument to read options from FILE. # UNKNOWN-ARG: unknown argument '{{-+}}abcabc' # NO-INPUT-FILES: no input file specified diff --git a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test --- a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test +++ b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test @@ -1,10 +1,10 @@ -# RUN: llvm-install-name-tool -h | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s -# RUN: llvm-install-name-tool --help | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s -# RUN: not llvm-install-name-tool 2>&1 | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s +# RUN: llvm-install-name-tool -h | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s --match-full-lines +# RUN: llvm-install-name-tool --help | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s --match-full-lines +# RUN: not llvm-install-name-tool 2>&1 | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s --match-full-lines # RUN: not llvm-install-name-tool -abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s # RUN: not llvm-install-name-tool --abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s -# INSTALL-NAME-TOOL-USAGE: USAGE: llvm-install-name-tool -# INSTALL-NAME-TOOL-USAGE: @FILE +# INSTALL-NAME-TOOL-USAGE: USAGE: llvm-install-name-tool [options] input +# INSTALL-NAME-TOOL-USAGE: Pass @FILE as argument to read options from FILE. # UNKNOWN-ARG: unknown argument '{{-+}}abcabc' diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp --- a/llvm/tools/llvm-objcopy/CopyConfig.cpp +++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp @@ -393,9 +393,30 @@ return Result; } +namespace { + +enum class ToolType { Objcopy, Strip, InstallNameTool }; + +} // anonymous namespace + static void printHelp(const opt::OptTable &OptTable, raw_ostream &OS, - StringRef ToolName) { - OptTable.PrintHelp(OS, (ToolName + " input [output]").str().c_str(), + ToolType Tool) { + StringRef HelpText, ToolName; + switch (Tool) { + case ToolType::Objcopy: + ToolName = "llvm-objcopy"; + HelpText = " [options] input [output]"; + break; + case ToolType::Strip: + ToolName = "llvm-strip"; + HelpText = " [options] inputs..."; + break; + case ToolType::InstallNameTool: + ToolName = "llvm-install-name-tool"; + HelpText = " [options] input"; + break; + } + OptTable.PrintHelp(OS, (ToolName + HelpText).str().c_str(), (ToolName + " tool").str().c_str()); // TODO: Replace this with libOption call once it adds extrahelp support. // The CommandLine library has a cl::extrahelp class to support this, @@ -416,12 +437,12 @@ T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount); if (InputArgs.size() == 0) { - printHelp(T, errs(), "llvm-objcopy"); + printHelp(T, errs(), ToolType::Objcopy); exit(1); } if (InputArgs.hasArg(OBJCOPY_help)) { - printHelp(T, outs(), "llvm-objcopy"); + printHelp(T, outs(), ToolType::Objcopy); exit(0); } @@ -807,12 +828,12 @@ T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount); if (InputArgs.size() == 0) { - printHelp(T, errs(), "llvm-install-name-tool"); + printHelp(T, errs(), ToolType::InstallNameTool); exit(1); } if (InputArgs.hasArg(INSTALL_NAME_TOOL_help)) { - printHelp(T, outs(), "llvm-install-name-tool"); + printHelp(T, outs(), ToolType::InstallNameTool); exit(0); } @@ -870,12 +891,12 @@ T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount); if (InputArgs.size() == 0) { - printHelp(T, errs(), "llvm-strip"); + printHelp(T, errs(), ToolType::Strip); exit(1); } if (InputArgs.hasArg(STRIP_help)) { - printHelp(T, outs(), "llvm-strip"); + printHelp(T, outs(), ToolType::Strip); exit(0); }