Skip to content

Commit a86bd22

Browse files
committed
[llvm-ar] Implement the V modifier as an alias for --version
Summary: Also update the help modifier (h) so that it works as a modifier and not just as a standalone `h`. For example, `llvm-ar h` prints the help message, but `llvm-ar xh` currently prints `unknown option h`. Reviewers: MaskRay, gbreynoo Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69007 llvm-svn: 375028
1 parent 87cf73e commit a86bd22

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

llvm/test/tools/llvm-ar/help-message.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
## Show that the help message for llvm-ar can be printed with either the long
2+
## flag -help or with the h modifier.
3+
14
# RUN: llvm-ar h | FileCheck %s
5+
# RUN: llvm-ar xh | FileCheck %s
26
# RUN: llvm-ar -h | FileCheck %s
7+
# RUN: llvm-ar -xh | FileCheck %s
38
# RUN: llvm-ar -help | FileCheck %s
49
# RUN: llvm-ar --help | FileCheck %s
510

llvm/test/tools/llvm-ar/version.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Show that the version for llvm-ar can be printed with either the long flag
2+
## -version or with the V modifier.
3+
4+
RUN: llvm-ar V | FileCheck %s
5+
RUN: llvm-ar xV | FileCheck %s
6+
RUN: llvm-ar -V | FileCheck %s
7+
RUN: llvm-ar -xV | FileCheck %s
8+
RUN: llvm-ar -version | FileCheck %s
9+
RUN: llvm-ar --version | FileCheck %s
10+
11+
CHECK: version

llvm/tools/llvm-ar/llvm-ar.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ USAGE: llvm-ar [options] [-]<operation>[modifiers] [relpos] [count] <archive> [f
100100
[b] - put [files] before [relpos] (same as [i])
101101
[c] - do not warn if archive had to be created
102102
[D] - use zero for timestamps and uids/gids (default)
103+
[h] - display this help and exit
103104
[i] - put [files] before [relpos] (same as [b])
104105
[l] - ignored for compatibility
105106
[L] - add archive's contents
@@ -112,6 +113,7 @@ USAGE: llvm-ar [options] [-]<operation>[modifiers] [relpos] [count] <archive> [f
112113
[u] - update only [files] newer than archive contents
113114
[U] - use actual timestamps and uids/gids
114115
[v] - be verbose about actions taken
116+
[V] - display the version and exit
115117
)";
116118

117119
void printHelpMessage() {
@@ -381,6 +383,12 @@ static ArchiveOperation parseCommandLine() {
381383
case 'L':
382384
AddLibrary = true;
383385
break;
386+
case 'V':
387+
cl::PrintVersionMessage();
388+
exit(0);
389+
case 'h':
390+
printHelpMessage();
391+
exit(0);
384392
default:
385393
fail(std::string("unknown option ") + Options[i]);
386394
}
@@ -1063,7 +1071,7 @@ static void runMRIScript() {
10631071
}
10641072

10651073
static bool handleGenericOption(StringRef arg) {
1066-
if (arg == "h" || arg.startswith("-h") || arg == "--help") {
1074+
if (arg == "-help" || arg == "--help") {
10671075
printHelpMessage();
10681076
return true;
10691077
}

0 commit comments

Comments
 (0)