Skip to content

[cli] Deprecate prefer command - #5475

Open
xmkg wants to merge 21 commits into
mainfrom
cli/deprecate-prefer
Open

xmkg wants to merge 21 commits into
mainfrom
cli/deprecate-prefer

Conversation

@xmkg

@xmkg xmkg commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

This PR deprecates the prefer command and also blocks context switching between the user's available alias contexts. The user can still list and migrate aliases to the default context manually if they want to.

User-facing changes:

Command Before After
multipass prefer <ctx> Switches (or creates) the active context Prints a deprecation warning, exits with an error, changes nothing
multipass alias ... Creates the alias in the active context Always creates it in default
multipass <alias> Runs aliases from the active context Runs aliases from default only; aliases from other contexts fail with a message on how to recreate them
multipass aliases Marks the active context with * Also shows a Context status column (active/inactive); JSON/YAML gain context-status/context_status
multipass unalias --all Clears the active context Clears all contexts

Existing aliases in non-default contexts are kept, not deleted or merged. They show as inactive in multipass aliases, and users can recreate them in default or remove them with unalias <context>.<name>.

Drive-by fixes:

  • launch showed "unable to create alias" for aliases that were actually created fine, and said nothing when one really failed. It now only warns about real failures.
  • multipass aliases could print an empty table with just the headers when there were no aliases left. It now says "No aliases defined." like it should.
  • Deleting an instance also deleted all aliases in a context that happened to have the same name, even aliases for other instances. For example, deleting an instance called default wiped every alias in default. Now it only removes the deleted instance's own aliases, and cleans up their scripts.

Updated tests and documentation as well.

MULTI-2692

@xmkg
xmkg requested a balanced review from Copilot October 22, 2026 13:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.17355% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.64%. Comparing base (4cf1cc5) to head (4b6252d).

Files with missing lines Patch % Lines
src/client/common/alias_dict.cpp 98.56% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5475      +/-   ##
==========================================
+ Coverage   79.58%   79.64%   +0.07%     
==========================================
  Files         359      359              
  Lines       19625    19619       -6     
==========================================
+ Hits        15616    15623       +7     
+ Misses       4009     3996      -13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xmkg
xmkg marked this pull request as ready for review October 23, 2026 09:15
@xmkg
xmkg requested review from a team and ricab and a balanced review from Copilot and removed request for a team October 23, 2026 09:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Completion parsing and legacy empty-context handling introduce user-visible regressions that remain unresolved.

2 open issues

Review effort: Balanced

Comment on lines +122 to +124
sub(/\r$/, "", $6)
if ($6 == "active") print $1
else if (command == "unalias") print $5 "." $1
Comment thread src/client/common/alias_dict.cpp Resolved
@ricab

ricab commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

This probably doesn't link in a comment, but for future reference: MULTI-2692

@ricab ricab left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to get into context and understand it all, but I think this is solid overall and doing what it means to.

However, I believe a few choices make this more complex that it should have to be, leaving more disperse code to remove in the second step (e.g. active_context field and setter). I also spotted some inconsistencies with respect to other deprecated commands.

One thing that would have helped me review this would be some more information in the description. I don't need anything very long and I don't mind if you skip non-applicable fields in the template, but a reference for what sort of interaction this aimed for, choices, and manual testing steps would have helped.

Finally, there is one commit here changing 30+ files. Splitting it by concern would ease review and future reference. In this case, I think that justifies the commit rewrite and force-push.

I haven't reviewed the docs yet — waiting for I/O to settle before that.

Comment thread completions/bash/multipass Resolved
Comment thread src/client/common/alias_dict.cpp Resolved
Comment thread src/client/common/alias_dict.cpp Resolved
Comment thread src/client/common/alias_dict.cpp Resolved
Comment thread src/client/common/alias_dict.cpp Resolved
Comment thread tests/unit/test_alias_dict.cpp Resolved
Comment thread tests/unit/test_alias_dict.cpp Resolved
Comment thread src/client/cli/argparser.cpp Resolved
@xmkg
xmkg force-pushed the cli/deprecate-prefer branch from 9be3f24 to dbdaa8c Compare November 19, 2026 10:33
Copilot AI balanced review requested due to automatic review settings November 19, 2026 10:33
@xmkg

xmkg commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Finally, there is one commit here changing 30+ files. Splitting it by concern would ease review and future reference. In this case, I think that justifies the commit rewrite and force-push.

Done, split into 8 commits based on concern.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues

Review effort: Lite

Comment thread tests/unit/test_cli_client.cpp Outdated
std::make_pair(std::string{"prefer"},
"Switch the current alias context. If it does not exist, create it "
"before switching.")));
std::make_pair(std::string{"prefer"}, "Alias contexts can no longer be switched.")));
Copilot AI balanced review requested due to automatic review settings November 19, 2026 10:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 181 to 191
{
execute_alias = aliases->get_alias(requested_command.toStdString());
if (execute_alias)
return prepare_alias_execution(requested_command);

if (aliases->is_inactive_alias(requested_command.toStdString()))
{
cerr << make_inactive_alias_warning(requested_command.toStdString());
return ParseCode::CommandLineError;
}
}
Comment on lines +77 to 83
cerr << mp::make_deprecation_warning(
"`multipass prefer`",
"Alias contexts can no longer be switched; only the default context is active. "
"Use unique alias names instead.");

return status;
}
Comment thread src/client/cli/cmd/unalias.cpp Resolved
Copilot AI balanced review requested due to automatic review settings November 19, 2026 11:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EXPECT_CALL(*mock_platform, remove_alias_script("secondary.com.mand")).Times(1);
EXPECT_CALL(*mock_platform, remove_alias_script("com.mand")).Times(1);

EXPECT_EQ(send_command({"unalias", "secondary.com.mand"}), mp::ReturnCode::Ok);
Comment thread src/client/common/alias_dict.cpp Outdated
Comment on lines +38 to +40
if (previous_context && previous_context->is_string() &&
previous_context->as_string() != mp::default_context_name)
cerr << mp::make_inactive_alias_context_warning(previous_context->as_string().c_str());
Copilot AI balanced review requested due to automatic review settings November 19, 2026 11:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Copilot AI balanced review requested due to automatic review settings November 19, 2026 12:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Copilot AI balanced review requested due to automatic review settings November 19, 2026 12:32
@xmkg
xmkg requested a review from ricab November 23, 2026 07:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

xmkg added 20 commits November 23, 2026 15:26
Launch warned about aliases that were created successfully and stayed
silent about the ones that failed. Warn only when alias creation fails.
Alias contexts can no longer be switched. Keep the prefer command so
existing scripts get a clear deprecation warning instead of an unknown
command error, but make it fail without changing the active context.
Alias contexts can no longer be switched, so AliasDict now enforces
"default" as the only active context instead of tracking it in state.
Drop the active_context member, set_active_context and
active_context_name. The default context always exists, even after it
is removed or the dictionary is cleared.

Legacy files that select another context still load. Their aliases are
kept but inactive, a warning explains how to recreate them, and the
file is only rewritten when the dictionary is modified. The
active-context field is still written as "default" so that older
releases can read the file.
Add a context status column (CSV and table) and a context status map
(JSON and YAML) so users can tell usable aliases in the default context
apart from definitions retained in inactive contexts.
Running an alias that only exists in an inactive context now fails with
a message explaining how to view its definition and recreate it in the
default context, instead of reporting an unknown command.
Since contexts can no longer be switched, aliases in inactive contexts
could not be removed in bulk. Make --all remove aliases from every
context.
Only offer aliases from the default context as commands. Qualified
names from inactive contexts are still offered to unalias, so they can
be removed.
Document that default is the only active context, how to recreate
aliases from inactive contexts, the new context status output, and the
deprecation of prefer.
@xmkg
xmkg force-pushed the cli/deprecate-prefer branch from f4719dd to 304307e Compare November 23, 2026 12:32
Copilot AI balanced review requested due to automatic review settings November 23, 2026 12:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 12:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants