-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
59 lines (52 loc) · 1.69 KB
/
Copy pathcli.py
File metadata and controls
59 lines (52 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import argparse
from .core import GitVersion
def main() -> None:
parser = argparse.ArgumentParser(
description="Extract version information from a Git repository.",
)
parser.add_argument(
"--prefix", "-p",
default="BUILD_VERSION",
help="Prefix for environment variable names (default: BUILD_VERSION)",
)
parser.add_argument(
"--repo", "-r",
default=None,
help="Path to the Git repository (default: current working directory)",
)
parser.add_argument(
"--tag-pattern", "-t",
default="v[0-9]*",
help="Glob pattern to match version tags (default: v[0-9]*)",
)
parser.add_argument(
"--safe-directory",
default=None,
help="Pass ``-c safe.directory=<value>`` to git commands. "
"Use ``'*'`` to allow all directories (useful in Docker containers).",
)
parser.add_argument(
"--property", "-P",
choices=[
"tag", "version", "version_major", "version_minor", "version_patch",
"build", "branch", "short", "full", "extended", "commit",
"default_branch", "release_branches", "env", "all",
],
default="all",
help="Which property to output (default: all)",
)
args = parser.parse_args()
gv = GitVersion(
repo_path=args.repo,
tag_pattern=args.tag_pattern,
safe_directory=args.safe_directory,
)
if args.property == "env":
for key, value in gv.env(prefix=args.prefix).items():
print(f"{key}={value}")
elif args.property == "all":
print(gv)
else:
print(getattr(gv, args.property))
if __name__ == "__main__":
main()