Skip to content

Commit 2d578c5

Browse files
committed
✨ create a minimal cli interface example
1 parent 5750798 commit 2d578c5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ requires = ["setuptools>=64", "setuptools_scm>=8"]
6868

6969
[tool.isort]
7070
profile = "black"
71+
72+
# Script entry points, i.e. command line commands available after installing the package
73+
# e.g. implemented using argparse
74+
# Then you can type: `python-package-hello -h` in the terminal
75+
[project.scripts]
76+
python-package-hello = "python_package.cli:main"

src/python_package/cli.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import argparse
2+
3+
from .mockup import hello_world
4+
5+
6+
def main():
7+
parser = argparse.ArgumentParser(description="Python Package CLI")
8+
parser.add_argument(
9+
"-n",
10+
"--repeat",
11+
type=int,
12+
default=1,
13+
help="Number of times to repeat the greeting hello world",
14+
)
15+
args = parser.parse_args()
16+
msg = hello_world(args.repeat)
17+
print(msg)

0 commit comments

Comments
 (0)