Skip to content

Commit bfc8483

Browse files
psafontydirson
authored andcommitted
cli: make the branch parameter non-optional
Now it's a positional argument. This needed a change in how the run subparser works: it needs to be set up last, and its nargs had to be changed to '*' to make it work in some occasions, like: ``` xcp-ng-dev container run 8.3 --help ``` Now it also allows to separate arguments using `--`: ``` xcp-ng-dev container run 8.3 -- bash --help ``` This was suggested by Yann Dirson Suggested-by: Yann Dirson <yann.dirson@vates.tech> Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent f36c1c0 commit bfc8483

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/xcp_ng_dev/cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
CONTAINER_PREFIX = "ghcr.io/xcp-ng/xcp-ng-build-env"
2020

21-
DEFAULT_BRANCH = '8.3'
2221
DEFAULT_ULIMIT_NOFILE = 2048
2322
RPMBUILD_STAGES = "abpfcilsrd" # valid X values in `rpmbuild -bX`
2423

@@ -40,9 +39,8 @@ def is_podman(runner):
4039
return False
4140

4241
def add_common_args(parser):
43-
parser.add_argument('-b', '--branch',
44-
help='XCP-ng version: 7.6, %s, etc. If not set, '
45-
'will default to %s.' % (DEFAULT_BRANCH, DEFAULT_BRANCH))
42+
parser.add_argument('branch',
43+
help='The version of XCP-ng to prepare for the build. For example, 8.3.')
4644
parser.add_argument('-n', '--no-exit', action='store_true',
4745
help='After finishing the execution of the action, drop user into a shell')
4846
parser.add_argument('-d', '--dir', action='append',
@@ -125,11 +123,13 @@ def buildparser():
125123
parser_run = subparsers_container.add_parser(
126124
'run',
127125
help='Execute a command inside a container')
128-
parser_run.add_argument(
129-
'command', nargs=argparse.REMAINDER,
130-
help='Command to run inside the prepared container')
131126
add_container_args(parser_run)
132127
add_common_args(parser_run)
128+
parser_run.add_argument(
129+
'command', nargs='*',
130+
help='Command with arguments to run inside the container, '
131+
'if the command has arguments that start with --, '
132+
'separate the arguments for this tool and the command with " -- ".')
133133

134134
# shell -- like run bash
135135
parser_shell = argparse.ArgumentParser()
@@ -143,7 +143,7 @@ def buildparser():
143143

144144
def container(args):
145145
build = args.action == 'build'
146-
branch = args.branch or DEFAULT_BRANCH
146+
branch = args.branch
147147
docker_arch = args.platform or ("linux/amd64/v2" if branch == "9.0" else "linux/amd64")
148148

149149
docker_args = [RUNNER, "run", "-i", "-t",

test/test.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ for REPO in ${REPOS}; do
1414
REPO_PATH=/tmp/"$REPO"
1515
git clone --branch "$TARGET_XCP_NG_VERSION" https://github.com/xcp-ng-rpms/"$REPO" "$REPO_PATH"
1616

17-
xcp-ng-dev container build "$REPO_PATH" \
17+
xcp-ng-dev container build "$REPO_PATH" "$TARGET_XCP_NG_VERSION" \
1818
--name "$CONTAINER_NAME" \
1919
--fail-on-error \
20-
-b "$TARGET_XCP_NG_VERSION" \
2120
--rm
2221

2322
rm -rf "$REPO_PATH"

0 commit comments

Comments
 (0)