Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cmd/bap-builder/CmdArgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ func (cmd *CmdLineArgs) ParseArgs(args []string) error {
cmd.BuildApp = cmd.buildAppParser.Happened()
cmd.CreateSysroot = cmd.createSysrootParser.Happened()

return cmd.checkInvalidOptionCombinations()
}

// checkInvalidOptionCombinations
// Return appropriate error when any invalid option combination is detected, else nil.
func (cmd *CmdLineArgs) checkInvalidOptionCombinations() error {
if cmd.BuildPackage {
if *cmd.BuildPackageArgs.Name == "" && !*cmd.BuildPackageArgs.All {
return fmt.Errorf("build-package requires either --name or --all")
}
}

if cmd.BuildApp {
if *cmd.BuildAppArgs.Name == "" && !*cmd.BuildAppArgs.All {
return fmt.Errorf("build-app requires either --name or --all")
}
}

if *cmd.BuildPackageArgs.All {
if *cmd.BuildPackageArgs.BuildDeps {
return fmt.Errorf("all and build-deps flags at the same time")
Expand Down
32 changes: 32 additions & 0 deletions tests/integration_tests/test_invalid_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,35 @@ def test_05_run_with_nonexisting_app(test_image, packager_binary, test_repo, con
stdout = result.communicate()[0]

assert "ERROR" in stdout


def test_06_build_package_without_name_or_all(test_image, packager_binary, context, test_repo):
"""Run build-package without --name or --all"""

result = run_packager(
packager_binary,
"build-package",
context=context,
image_name=test_image,
output_dir=test_repo,
expected_returncode=PackagerReturnCode.CMD_LINE_ERROR,
)
stdout = result.communicate()[0]

assert "ERROR" in stdout


def test_07_build_app_without_name_or_all(test_image, packager_binary, context, test_repo):
"""Run build-app without --name or --all"""

result = run_packager(
packager_binary,
"build-app",
context=context,
image_name=test_image,
output_dir=test_repo,
expected_returncode=PackagerReturnCode.CMD_LINE_ERROR,
)
stdout = result.communicate()[0]

assert "ERROR" in stdout
Loading