Skip to content
Draft
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
4 changes: 4 additions & 0 deletions conan/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

_CONAN_INTERNAL_CUSTOM_COMMANDS_PATH = "_CONAN_INTERNAL_CUSTOM_COMMANDS_PATH"

# Short aliases mapped to their canonical command names
_COMMAND_ALIASES = {"ws": "workspace"}


class Cli:
"""A single command of the conan application, with all the first level commands. Manages the
Expand Down Expand Up @@ -174,6 +177,7 @@ def run(self, *args):
except IndexError: # No parameters
self._output_help_cli()
return
command_argument = _COMMAND_ALIASES.get(command_argument, command_argument)
try:
command = self._commands[command_argument]
except KeyError as exc:
Expand Down
20 changes: 20 additions & 0 deletions test/integration/workspace/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@
from conan.tools.files import replace_in_file


class TestWorkspaceAlias:

def test_ws_alias_dispatches_to_workspace(self):
# 'ws' behaves as 'workspace' for both the base command and its subcommands
c = TestClient(light=True)
c.save({"conanws.yml": ""})
c.run("ws root")
assert c.current_folder in c.stdout

c.run("ws info")
assert "packages: (empty)" in c.out

def test_ws_alias_not_in_help_listing(self):

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.

Maybe we can make it visible adding the alias in the --help output? Something like this?

$ conan --help

Consumer commands
cache          Perform file operations in the local cache (of recipes and/or packages).
...
workspace (ws) Manage Conan workspaces (group of packages in editable mode)
...

c = TestClient(light=True)
c.run("-h")
assert "workspace" in c.stdout
for line in c.stdout.splitlines():
assert not line.strip().startswith("ws "), line


class TestWorkspaceRoot:

def test_workspace_root(self):
Expand Down
Loading