Skip to content

Commit 8c8a09f

Browse files
committed
feat: add app file for CLI
1 parent ce68bce commit 8c8a09f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/diffpy/cmi/app.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import getopt
2+
import sys
3+
4+
5+
def usage():
6+
"""Print short help message."""
7+
print(
8+
"""\
9+
10+
DiffPy-CMI is our complex modeling framework. It is a highly flexible library
11+
of Python modules for robust modeling of nanostructures in crystals,
12+
nanomaterials, and amorphous materials.
13+
14+
Docs: https://www.diffpy.org/diffpy.cmi
15+
16+
Usage:
17+
diffpy-cmi [--version] [--help]
18+
19+
Options:
20+
-V, --version Show version and exit
21+
-h, --help Show this message and exit
22+
"""
23+
)
24+
25+
26+
def version():
27+
from diffpy.cmi.version import __version__
28+
29+
print(f"diffpy-cmi {__version__}")
30+
31+
32+
def main():
33+
try:
34+
opts, args = getopt.gnu_getopt(sys.argv[1:], "hV", ["help", "version"])
35+
except getopt.GetoptError as err:
36+
print(f"Error: {err}", file=sys.stderr)
37+
usage()
38+
sys.exit(1)
39+
40+
for opt, _ in opts:
41+
if opt in ("-h", "--help"):
42+
usage()
43+
return
44+
elif opt in ("-V", "--version"):
45+
version()
46+
return
47+
48+
# Default behavior (if no arguments)
49+
usage()
50+
51+
52+
if __name__ == "__main__":
53+
main()

0 commit comments

Comments
 (0)