Skip to content

Commit 89328df

Browse files
committed
feat: use argsparse description feature
1 parent a247ec6 commit 89328df

File tree

1 file changed

+17
-59
lines changed

1 file changed

+17
-59
lines changed

src/diffpy/cmi/app.py

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,32 @@
11
import argparse
2-
import sys
32

43
from diffpy.cmi.version import __version__
54

65

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-
456
def main():
467
parser = argparse.ArgumentParser(
478
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,
5215
)
16+
5317
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",
5521
)
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+
6725
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()
7230

7331

7432
if __name__ == "__main__":

0 commit comments

Comments
 (0)