Skip to content

Feature: Parse reference attributes from --ref in workspace add (#20261) - #20269

Merged
memsharded merged 1 commit into
conan-io:develop2from
omsadegaonkar:feature/20261-parse-ref
Aug 27, 2026
Merged

Feature: Parse reference attributes from --ref in workspace add (#20261)#20269
memsharded merged 1 commit into
conan-io:develop2from
omsadegaonkar:feature/20261-parse-ref

Conversation

@omsadegaonkar

@omsadegaonkar omsadegaonkar commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Changelog: Feature: Parse reference attributes from --ref in workspace add.
Docs: Omit

  • Removed mutual exclusion check for path and --ref
  • Added parsing of --ref to extract name, version, user, channel
  • Uses RecipeReference.loads() for robust parsing
  • Added clear error message for invalid reference format

fixes #20261

@CLAassistant

CLAassistant commented Aug 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@memsharded memsharded left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some unit test would be necessary for this feature, please try to add some (likely to go in the integration folder, the easier is using the TestClient helper), and ask for guidance if necessary.

Many thanks for your contribution!

group.add_argument("-nr", "--no-remote", action="store_true",
help='Do not use remote, resolve exclusively in the cache')
args = parser.parse_args(*args)
if args.path and args.ref:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this check changed? Seems mostly unrelated to the parsing of --ref

Comment thread conan/cli/commands/workspace.py Outdated
ref = conan_api.workspace.add(path,
args.name, args.version, args.user, args.channel,
cwd, args.output_folder, remotes=remotes)
elif not path:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same above, I am not sure why this check was changed.

Comment thread conan/cli/commands/workspace.py Outdated

if args.ref:
# TODO: Use path here to open in this path
if '/' in args.ref or '@' in args.ref:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The --ref should be parsed in any case, it is not intended that --ref can be an incomplete reference with only the name, for that purpose the individual arguments are there.

Probably the RecipeReference validation could be used?
Also, once the RecipeReference is loaded, it doesn't make sense to mix it with individual arguments, it should be either --ref or the individual arguments, but not both. Maybe for that case, an extra check could be added, but not necessary in this PR, this PR can keep focused on the parsing.

@memsharded

Copy link
Copy Markdown
Member

Hi @omsadegaonkar

Conan 2.32 release is approaching, if we want this in, it would be necessary to address these things this week. Otherwise, it will have to wait until 2.33 next month. Thanks!

@omsadegaonkar

Copy link
Copy Markdown
Contributor Author

hey @memsharded Thanks for the review.

The mutual exclusion test was stripped out in an earlier commit, but now it's back in the latest version, also the things u said are taken care of now inside the new commit, like parsing and more.
created a new commit here: 71a7be7

The PR now only deals with parsing of --ref without any other changes.
And I've included integration tests with TestClient as asked. The 3 tests are passing locally.
Thank you.

Screenshot from 2026-08-26 17-31-47

@memsharded memsharded left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please merge from develop2 to avoid conflicts

Comment thread conan/cli/commands/workspace.py Outdated
Comment on lines +68 to +81
# --- PARSING LOGIC
name = args.name
version = args.version
user = args.user
channel = args.channel

if args.ref:
# TODO: Use path here to open in this path
from conan.api.model import RecipeReference
try:
parsed_ref = RecipeReference.loads(args.ref)
name = parsed_ref.name
version = parsed_ref.version
user = parsed_ref.user
channel = parsed_ref.channel

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This still allows definition of both arguments, silently ignoring some arguments.

When args.ref is defined, it means args.name/version/user/channel cannot be defined, and defining both should raise an error, that would be better.

client.run("export . --user=company")

client.run("workspace init .")
client.run("workspace add --ref mypkg/1.0@company --version=2.0")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should raise an error, because of defining both arguments.

Comment thread test/integration/workspace/test_workspace_ref_parse.py
Comment on lines -49 to -51
"""
Add packages to current workspace
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If something is just format/style, better not change it

Comment thread conan/cli/commands/workspace.py Outdated
subparser.add_argument("-of", "--output-folder",
help='The root output folder for generated and build files')
subparser.add_argument("--ref", help="Open and add this reference (format: name/version@user/channel)")
subparser.add_argument("-of", "--output-folder", help='The root output folder for generated and build files')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same, avoid formatting changes

Comment thread conan/cli/commands/workspace.py Outdated
help='Do not use remote, resolve exclusively in the cache')
args = parser.parse_args(*args)

# keeping the check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove these lines, nothing changed here

…n-io#20261)

- Removed mutual exclusion check for path and --ref
- Added parsing of --ref to extract name, version, user, channel
- Uses RecipeReference.loads() for robust parsing
- Added clear error message for invalid reference format

fixes conan-io#20261
@omsadegaonkar
omsadegaonkar force-pushed the feature/20261-parse-ref branch from 5abd67b to 750a4ef Compare August 26, 2026 15:23
@omsadegaonkar

Copy link
Copy Markdown
Contributor Author

Hello @memsharded , I've cleaned up the branch history and updated the implementation. Only the integration tests and the expected workspace --ref parsing change are included in the most recent commit.
The final difference between upstream and develop2 is just two files, +53/-1, and three out of three tests are passing.
check out this most recent commit.

Thank you! here it is : omsadegaonkar@750a4ef

@memsharded memsharded added this to the 2.32.0 milestone Aug 26, 2026
@memsharded
memsharded merged commit 226b40a into conan-io:develop2 Aug 27, 2026
1 check passed
@memsharded

Copy link
Copy Markdown
Member

Merged, will be in 2.32, thanks for the contribution!

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.

[feature] Parse reference attributes from reference when using conan workspace add --ref

3 participants