Skip to content

Commit 71a1be4

Browse files
build-with-container: add argument groups to organize options
Use the argparse add_argument_group feature to organize the mass of arguments into more sensible categories. Hopefully, someone reading over the `--help` output can now more easily see options that are useful rather than being overwhelmed by a wall of text. Signed-off-by: John Mulligan <[email protected]>
1 parent 8734358 commit 71a1be4

File tree

1 file changed

+126
-91
lines changed

1 file changed

+126
-91
lines changed

src/script/build-with-container.py

Lines changed: 126 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -948,80 +948,113 @@ def parse_cli(build_step_names):
948948
formatter_class=argparse.RawDescriptionHelpFormatter,
949949
)
950950
parser.add_argument(
951-
"--debug",
951+
"--help-build-steps",
952952
action="store_true",
953-
help="Emit debugging level logging and tracebacks",
954-
)
955-
parser.add_argument(
956-
"--container-engine",
957-
help="Select container engine to use (eg. podman, docker)",
953+
help="Print executable build steps and brief descriptions",
958954
)
959-
parser.add_argument(
960-
"--cwd",
961-
help="Change working directory before executing commands",
955+
956+
g_basic = parser.add_argument_group(
957+
title="Basic options",
962958
)
963-
parser.add_argument(
959+
g_basic.add_argument(
964960
"--distro",
965961
"-d",
966962
choices=DistroKind.aliases().keys(),
967963
type=DistroKind.from_alias,
968964
default=str(DistroKind.CENTOS9),
969965
help="Specify a distro short name",
970966
)
971-
parser.add_argument(
967+
g_basic.add_argument(
968+
"--execute",
969+
"-e",
970+
dest="steps",
971+
action="append",
972+
choices=build_step_names,
973+
help="Execute the target build step(s)",
974+
)
975+
g_basic.add_argument(
976+
"--cwd",
977+
help="Change working directory before executing commands",
978+
)
979+
g_basic.add_argument(
980+
"--build-dir",
981+
"-b",
982+
help=(
983+
"Specify a build directory relative to the home dir"
984+
" (the ceph source root)"
985+
),
986+
)
987+
g_basic.add_argument(
988+
"--env-file",
989+
type=pathlib.Path,
990+
help="Use this environment file when building",
991+
)
992+
993+
g_debug = parser.add_argument_group(
994+
title="Debugging options",
995+
)
996+
g_debug.add_argument(
997+
"--debug",
998+
action="store_true",
999+
help="Emit debugging level logging and tracebacks",
1000+
)
1001+
g_debug.add_argument(
1002+
"--dry-run",
1003+
action="store_true",
1004+
help="Do not execute key commands, print and continue if possible",
1005+
)
1006+
g_debug.add_argument(
1007+
"--no-prereqs",
1008+
"-P",
1009+
action="store_true",
1010+
help="Do not execute any prerequisite steps. Only execute specified steps",
1011+
)
1012+
1013+
g_image = parser.add_argument_group(
1014+
title="Build image configuration",
1015+
description=(
1016+
'These options customize what and how the "Build Image" is'
1017+
" constructed"
1018+
),
1019+
)
1020+
g_image.add_argument(
9721021
"--tag",
9731022
"-t",
9741023
help="Specify a container tag. Append to the auto generated tag"
9751024
" by prefixing the supplied value with the plus (+) character",
9761025
)
977-
parser.add_argument(
1026+
g_image.add_argument(
9781027
"--base-branch",
9791028
help="Specify a base branch name",
9801029
)
981-
parser.add_argument(
1030+
g_image.add_argument(
9821031
"--current-branch",
9831032
help="Manually specify the current branch name",
9841033
)
985-
parser.add_argument(
1034+
g_image.add_argument(
9861035
"--image-repo",
9871036
help="Specify a container image repository",
9881037
)
989-
parser.add_argument(
1038+
g_image.add_argument(
9901039
"--image-sources",
9911040
"-I",
9921041
type=ImageSource.argument,
9931042
help="Specify a set of valid image sources. "
9941043
f"May be a comma separated list of {ImageSource.hint()}",
9951044
)
996-
parser.add_argument(
1045+
g_image.add_argument(
9971046
"--base-image",
9981047
help=(
9991048
"Supply a custom base image to use instead of the default"
10001049
" image for the source distro."
10011050
),
10021051
)
1003-
parser.add_argument(
1052+
g_image.add_argument(
10041053
"--homedir",
10051054
default="/ceph",
10061055
help="Container image home/build dir",
10071056
)
1008-
parser.add_argument(
1009-
"--dnf-cache-path",
1010-
help="DNF caching using provided base dir (during build-container build)",
1011-
)
1012-
parser.add_argument(
1013-
"--npm-cache-path",
1014-
help="NPM caching using provided base dir (during build)",
1015-
)
1016-
parser.add_argument(
1017-
"--build-dir",
1018-
"-b",
1019-
help=(
1020-
"Specify a build directory relative to the home dir"
1021-
" (the ceph source root)"
1022-
),
1023-
)
1024-
parser.add_argument(
1057+
g_image.add_argument(
10251058
"--build-arg",
10261059
dest="build_args",
10271060
action="append",
@@ -1030,7 +1063,37 @@ def parse_cli(build_step_names):
10301063
" Can be used to override default build image behavior."
10311064
),
10321065
)
1033-
parser.add_argument(
1066+
g_image.add_argument(
1067+
"--containerfile",
1068+
default="Dockerfile.build",
1069+
help="Specify the path to a (build) container file",
1070+
)
1071+
g_image.add_argument(
1072+
"--containerdir",
1073+
default=".",
1074+
help="Specify the path to container context dir",
1075+
)
1076+
1077+
g_container = parser.add_argument_group(
1078+
title="Container options",
1079+
description="Options to control how the containers are run",
1080+
)
1081+
g_container.add_argument(
1082+
"--container-engine",
1083+
help="Select container engine to use (eg. podman, docker)",
1084+
)
1085+
g_container.add_argument(
1086+
"--extra",
1087+
"-x",
1088+
action="append",
1089+
help="Specify an extra argument to pass to container command",
1090+
)
1091+
g_container.add_argument(
1092+
"--keep-container",
1093+
action="store_true",
1094+
help="Skip removing container after executing command",
1095+
)
1096+
g_container.add_argument(
10341097
"--overlay-dir",
10351098
"-l",
10361099
help=(
@@ -1039,52 +1102,46 @@ def parse_cli(build_step_names):
10391102
"use a temporary overlay (discarding writes on container exit)"
10401103
),
10411104
)
1042-
parser.add_argument(
1105+
1106+
g_caching = parser.add_argument_group(
1107+
title="Persistent cache options",
1108+
description=(
1109+
"Options to control caches that persist after the containers"
1110+
" have exited"
1111+
),
1112+
)
1113+
g_caching.add_argument(
1114+
"--dnf-cache-path",
1115+
help="DNF caching using provided base dir (during build-container build)",
1116+
)
1117+
g_caching.add_argument(
1118+
"--npm-cache-path",
1119+
help="NPM caching using provided base dir (during build)",
1120+
)
1121+
g_caching.add_argument(
10431122
"--ccache-dir",
10441123
help=(
10451124
"Specify a directory (within the container) to save ccache"
10461125
" output"
10471126
),
10481127
)
1049-
parser.add_argument(
1050-
"--extra",
1051-
"-x",
1052-
action="append",
1053-
help="Specify an extra argument to pass to container command",
1054-
)
1055-
parser.add_argument(
1056-
"--keep-container",
1057-
action="store_true",
1058-
help="Skip removing container after executing command",
1059-
)
1060-
parser.add_argument(
1061-
"--containerfile",
1062-
default="Dockerfile.build",
1063-
help="Specify the path to a (build) container file",
1064-
)
1065-
parser.add_argument(
1066-
"--containerdir",
1067-
default=".",
1068-
help="Specify the path to container context dir",
1069-
)
1070-
parser.add_argument(
1071-
"--no-prereqs",
1072-
"-P",
1073-
action="store_true",
1074-
help="Do not execute any prerequisite steps. Only execute specified steps",
1128+
1129+
g_pkg = parser.add_argument_group(
1130+
title="RPM & DEB package build options",
1131+
description="Options specific to building packages",
10751132
)
1076-
parser.add_argument(
1133+
g_pkg.add_argument(
10771134
"--rpm-no-match-sha",
10781135
dest="srpm_match",
10791136
action="store_const",
1080-
const='any',
1137+
const="any",
10811138
help=(
10821139
"Do not try to build RPM packages that match the SHA of the current"
10831140
" git checkout. Use any source RPM available."
10841141
" [DEPRECATED] Use --rpm-match=any"
10851142
),
10861143
)
1087-
parser.add_argument(
1144+
g_pkg.add_argument(
10881145
"--srpm-match",
10891146
dest="srpm_match",
10901147
choices=("any", "versionglob", "auto"),
@@ -1096,39 +1153,17 @@ def parse_cli(build_step_names):
10961153
" 'auto' (the default) uses a version derived from ceph.spec."
10971154
),
10981155
)
1099-
parser.add_argument(
1156+
g_pkg.add_argument(
11001157
"--rpmbuild-arg",
1101-
'-R',
1158+
"-R",
11021159
action="append",
11031160
help="Pass this extra argument to rpmbuild",
11041161
)
1105-
parser.add_argument(
1162+
g_pkg.add_argument(
11061163
"--ceph-version",
11071164
help="Rather than infer the Ceph version, use this value",
11081165
)
1109-
parser.add_argument(
1110-
"--execute",
1111-
"-e",
1112-
dest="steps",
1113-
action="append",
1114-
choices=build_step_names,
1115-
help="Execute the target build step(s)",
1116-
)
1117-
parser.add_argument(
1118-
"--env-file",
1119-
type=pathlib.Path,
1120-
help="Use this environment file when building",
1121-
)
1122-
parser.add_argument(
1123-
"--dry-run",
1124-
action="store_true",
1125-
help="Do not execute key commands, print and continue if possible",
1126-
)
1127-
parser.add_argument(
1128-
"--help-build-steps",
1129-
action="store_true",
1130-
help="Print executable build steps and brief descriptions",
1131-
)
1166+
11321167
cli, rest = parser.parse_my_args()
11331168
if cli.help_build_steps:
11341169
print("Executable Build Steps")

0 commit comments

Comments
 (0)