@@ -18,6 +18,49 @@ def cli():
1818 pass
1919
2020
21+ @click .command ()
22+ def version () -> None :
23+ """Display the installed version of warnet"""
24+ try :
25+ from warnet ._version import __version__
26+
27+ # For PyPI releases, this will be the exact tag (e.g. "1.1.11")
28+ # For dev installs, it will be something like "1.1.11.post1.dev17+g27af3a7.d20250309"
29+ # Which is <tag>.post<postN>.dev<devN>+g<git commit hash>.d<YYYYMMDD>
30+ # <postN> is the number of local commits since the checkout commit
31+ # <devN> is the number of commits since the last tag
32+ raw_version = __version__
33+
34+ # Format the version string to our desired format
35+ if "+" in raw_version :
36+ version_part , git_date_part = raw_version .split ("+" , 1 )
37+
38+ # Get just the git commit hash
39+ commit_hash = (
40+ git_date_part [1 :].split ("." , 1 )[0 ]
41+ if git_date_part .startswith ("g" )
42+ else git_date_part .split ("." , 1 )[0 ]
43+ )
44+
45+ # Remove .dev component (from "no-guess-dev" scheme)
46+ clean_version = version_part
47+ if ".dev" in clean_version :
48+ clean_version = clean_version .split (".dev" )[0 ]
49+
50+ # Apply dirty status (from "no-guess-dev" scheme)
51+ if ".post" in clean_version :
52+ base = clean_version .split (".post" )[0 ]
53+ version_str = f"{ base } -{ commit_hash } -dirty"
54+ else :
55+ version_str = f"{ clean_version } -{ commit_hash } "
56+ else :
57+ version_str = raw_version
58+
59+ click .echo (f"warnet version { version_str } " )
60+ except ImportError :
61+ click .echo ("warnet version unknown" )
62+
63+
2164cli .add_command (admin )
2265cli .add_command (auth )
2366cli .add_command (bitcoin )
@@ -37,7 +80,7 @@ def cli():
3780cli .add_command (status )
3881cli .add_command (stop )
3982cli .add_command (create )
40-
83+ cli . add_command ( version )
4184
4285if __name__ == "__main__" :
4386 cli ()
0 commit comments