Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6b1e3a3

Browse files
committed
python-userland: Show version information in --help
1 parent 176e38e commit 6b1e3a3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

userland/__init__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import importlib
2+
import importlib.metadata
23
import sys
34
from pathlib import Path
45

@@ -8,11 +9,18 @@
89

910

1011
def print_usage(prog_name: str) -> None:
12+
try:
13+
version = importlib.metadata.version(__package__)
14+
except importlib.metadata.PackageNotFoundError:
15+
version = "(unknown version)"
16+
1117
print(
12-
f"Usage: {prog_name} APPLET [ARGUMENT]..."
13-
+ f"\n{7 * " "}{prog_name} --list"
14-
+ "\n\nAvailable applets:",
18+
f"python-userland v{version}",
19+
f"Usage: {prog_name} APPLET [ARGUMENT]...",
20+
f"{7 * " "}{prog_name} --list",
21+
"\nAvailable applets:",
1522
", ".join(sorted(applets)),
23+
sep="\n"
1624
)
1725

1826

0 commit comments

Comments
 (0)