Skip to content

Commit 0544dde

Browse files
committed
feat: print brief description, doc location, and other flags
1 parent cc0daa3 commit 0544dde

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

src/diffpy/cmi/app.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,53 @@
1-
from diffpy.cmi.version import __version__
1+
import getopt
2+
import sys
3+
4+
5+
def usage():
6+
"""Print short help message."""
7+
print(
8+
"""\
9+
diffpy.cmi – Complex Modeling Infrastructure
10+
11+
DiffPy-CMI is our complex modeling framework. It is a highly flexible library
12+
of Python modules for robust modeling of nanostructures in crystals,
13+
nanomaterials, and amorphous materials.
14+
15+
Docs: https://www.diffpy.org/diffpy.cmi
16+
17+
Usage:
18+
diffpy-cmi [--version] [--help]
19+
20+
Options:
21+
-V, --version Show version and exit
22+
-h, --help Show this message and exit
23+
"""
24+
)
25+
26+
27+
def version():
28+
from diffpy.cmi.version import __version__
29+
30+
print(f"diffpy-cmi {__version__}")
231

332

433
def main():
5-
print(f"diffpy.cmi version: {__version__}")
34+
try:
35+
opts, args = getopt.gnu_getopt(sys.argv[1:], "hV", ["help", "version"])
36+
except getopt.GetoptError as err:
37+
print(f"Error: {err}", file=sys.stderr)
38+
usage()
39+
sys.exit(1)
40+
41+
for opt, _ in opts:
42+
if opt in ("-h", "--help"):
43+
usage()
44+
return
45+
elif opt in ("-V", "--version"):
46+
version()
47+
return
48+
49+
# Default behavior (if no arguments)
50+
usage()
651

752

853
if __name__ == "__main__":

0 commit comments

Comments
 (0)