diff --git a/changelog.d/+profiles-option.bugfix.md b/changelog.d/+profiles-option.bugfix.md new file mode 100644 index 0000000..47b4c62 --- /dev/null +++ b/changelog.d/+profiles-option.bugfix.md @@ -0,0 +1,3 @@ +`--profile` now selects the profile for `eb-local profiles`. It wins +over `EB_LOCAL_PROFILE` and `default_profile`, and an unknown name is +refused. diff --git a/src/main.zig b/src/main.zig index 700afd3..ab9d4d7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2796,7 +2796,7 @@ fn cmdProfiles(c: Ctx, g: Global) u8 { const sources = configSources(c, g); // Loading checks every profile in every file. var d: config.Diagnostic = .{}; - _ = config.load(a, sources, c.env, .{}, &d) catch |e| switch (e) { + _ = config.load(a, sources, c.env, .{ .profile = g.profile, .project = g.project, .buildenv = g.buildenv }, &d) catch |e| switch (e) { error.Invalid => die("{s}", .{d.message}), error.OutOfMemory => oom(), }; diff --git a/tests/test_config_cli.py b/tests/test_config_cli.py index 393ce0b..707bec7 100644 --- a/tests/test_config_cli.py +++ b/tests/test_config_cli.py @@ -301,6 +301,15 @@ def test_profiles_lists_every_profile(self): self.assertIn("mine", run.stdout) self.assertIn("licensed", run.stdout) + def test_profiles_option_overrides_environment_profile(self): + missing = self.run_tool(["--profile", "nope", "profiles"], EB_LOCAL_PROFILE="mine") + self.assertEqual(missing.returncode, 2, missing.stderr) + self.assertIn("no profile 'nope'", missing.stderr) + named = self.run_tool(["--profile", "mine", "profiles"], EB_LOCAL_PROFILE="nope") + self.assertEqual(named.returncode, 0, named.stderr) + self.assertIn("mine", named.stdout) + self.assertIn("licensed", named.stdout) + def test_default_profile_type_checked_when_overridden(self): self.user.write_text('default_profile = 123\n\n[profile.mine]\nprefix = "/tmp/p"\n') for args, extra_env in (