|
2 | 2 | # SPDX-License-Identifier: CC0-1.0 |
3 | 3 |
|
4 | 4 | """\ |
5 | | -Read .note.dlopen notes from ELF files and report the contents |
| 5 | +Read .note.dlopen notes from ELF files and report the contents. |
6 | 6 | """ |
7 | 7 |
|
8 | 8 | import argparse |
@@ -118,23 +118,43 @@ def group_by_feature(filenames, notes): |
118 | 118 |
|
119 | 119 | return features |
120 | 120 |
|
121 | | -def parse_args(): |
122 | | - p = argparse.ArgumentParser(description=__doc__) |
123 | | - p.add_argument('--raw', |
| 121 | +def make_parser(): |
| 122 | + p = argparse.ArgumentParser( |
| 123 | + description=__doc__, |
| 124 | + allow_abbrev=False, |
| 125 | + add_help=False, |
| 126 | + epilog='If no option is specifed, --raw is the default.', |
| 127 | + ) |
| 128 | + p.add_argument('-r', '--raw', |
124 | 129 | action='store_true', |
125 | | - help='show the original JSON extracted from input files') |
126 | | - p.add_argument('--sonames', |
| 130 | + help='Show the original JSON extracted from input files') |
| 131 | + p.add_argument('-s', '--sonames', |
127 | 132 | action='store_true', |
128 | | - help='list all sonames and their priorities, one soname per line') |
129 | | - p.add_argument('--features', |
| 133 | + help='List all sonames and their priorities, one soname per line') |
| 134 | + p.add_argument('-f', '--features', |
130 | 135 | nargs='?', |
131 | 136 | const=[], |
132 | 137 | type=lambda s: s.split(','), |
133 | 138 | action='extend', |
134 | 139 | metavar='FEATURE1,FEATURE2', |
135 | | - help='describe features, can be specified multiple times') |
136 | | - p.add_argument('filenames', nargs='+', metavar='filename') |
137 | | - return p.parse_args() |
| 140 | + help='Describe features, can be specified multiple times') |
| 141 | + p.add_argument('filenames', |
| 142 | + nargs='+', |
| 143 | + metavar='filename', |
| 144 | + help='Library file to extract notes from') |
| 145 | + p.add_argument('-h', '--help', |
| 146 | + action='help', |
| 147 | + help='Show this help message and exit') |
| 148 | + return p |
| 149 | + |
| 150 | +def parse_args(): |
| 151 | + args = make_parser().parse_args() |
| 152 | + |
| 153 | + if not args.raw and args.features is None and not args.sonames: |
| 154 | + # Make --raw the default if no action is specified. |
| 155 | + args.raw = True |
| 156 | + |
| 157 | + return args |
138 | 158 |
|
139 | 159 | if __name__ == '__main__': |
140 | 160 | args = parse_args() |
|
0 commit comments