|
1 | 1 | import argparse
|
2 |
| -import sys |
3 | 2 |
|
4 | 3 | from diffpy.cmi.version import __version__
|
5 | 4 |
|
6 | 5 |
|
7 |
| -def usage(): |
8 |
| - """Print full help message.""" |
9 |
| - print( |
10 |
| - """\ |
11 |
| -
|
12 |
| -Welcome to diffpy-CMI, a complex modeling infrastructure |
13 |
| -designed for multi-modal analysis of scientific data. |
14 |
| -While broadly applicable to a wide range of problems, |
15 |
| -including those beyond materials science, diffpy-CMI currently |
16 |
| -provides robust tools for modeling atomic structure based on |
17 |
| -Pair Distribution Function (PDF) and Small-Angle Scattering (SAS) data. |
18 |
| -Its modular Python architecture enables extensible workflows, |
19 |
| -with additional capabilities continually being developed. |
20 |
| -
|
21 |
| -Docs: https://www.diffpy.org/diffpy.cmi |
22 |
| -
|
23 |
| -Usage: |
24 |
| - diffpy-cmi [--version] [--help] |
25 |
| -
|
26 |
| -Options: |
27 |
| - --version Show version and exit |
28 |
| - -h, --help Show this message and exit |
29 |
| -""" |
30 |
| - ) |
31 |
| - |
32 |
| - |
33 |
| -def short_usage(): |
34 |
| - """Print brief usage message for invalid input.""" |
35 |
| - print( |
36 |
| - "Usage: diffpy-cmi [--version] [--help]\nUse --help to see more.", |
37 |
| - file=sys.stderr, |
38 |
| - ) |
39 |
| - |
40 |
| - |
41 |
| -def print_version(): |
42 |
| - print(f"diffpy-cmi {__version__}") |
43 |
| - |
44 |
| - |
45 | 6 | def main():
|
46 | 7 | parser = argparse.ArgumentParser(
|
47 | 8 | prog="diffpy-cmi",
|
48 |
| - add_help=False, |
49 |
| - ) |
50 |
| - parser.add_argument( |
51 |
| - "--version", action="store_true", help="Show version and exit" |
| 9 | + description=( |
| 10 | + "Welcome to diffpy-CMI, a complex modeling infrastructure " |
| 11 | + "for multi-modal analysis of scientific data.\n\n" |
| 12 | + "Docs: https://www.diffpy.org/diffpy.cmi" |
| 13 | + ), |
| 14 | + formatter_class=argparse.RawDescriptionHelpFormatter, |
52 | 15 | )
|
| 16 | + |
53 | 17 | parser.add_argument(
|
54 |
| - "-h", "--help", action="store_true", help="Show this message and exit" |
| 18 | + "--version", |
| 19 | + action="store_true", |
| 20 | + help="Show the program's version number and exit", |
55 | 21 | )
|
56 |
| - args, unknown = parser.parse_known_args() |
57 |
| - if unknown: |
58 |
| - print( |
59 |
| - f"Error: unrecognized arguments: {' '.join(unknown)}", |
60 |
| - file=sys.stderr, |
61 |
| - ) |
62 |
| - short_usage() |
63 |
| - sys.exit(1) |
64 |
| - if args.help: |
65 |
| - usage() |
66 |
| - return |
| 22 | + |
| 23 | + args = parser.parse_args() |
| 24 | + |
67 | 25 | if args.version:
|
68 |
| - print_version() |
69 |
| - return |
70 |
| - # Default behavior (no args) |
71 |
| - usage() |
| 26 | + print(f"diffpy-cmi {__version__}") |
| 27 | + else: |
| 28 | + # Default behavior when no arguments are given |
| 29 | + parser.print_help() |
72 | 30 |
|
73 | 31 |
|
74 | 32 | if __name__ == "__main__":
|
|
0 commit comments