Skip to content

CLI: skip adding sync as a command in dagger call #6517

Closed as not planned
Closed as not planned

Description

@helderco

Background

With #6359, If the last argument in dagger call is a Container, Directory, or File, the sync field is selected automatically, while the returned ID is ignored (not printed to screen). You can, however, select sync explicitly, in which case the ID is printed.

Motivation

For consistency, we want to just do the forced evaluation, without printing the returned ID to the user because there’s no meaning in this context. However, we don’t want to exclude printing all IDs because there may be some use cases for it:

Rationale

We already select sync automatically if the chain ends in an object that supports it because it makes sense as a default1. Supporting the use of sync explicitly adds redundancy and extra work if we don’t want to print the resulting ID:

  • TypeDefKind doesn’t support scalars at the moment, so when looking at the type definition from an explicit sync, it’s a string. In other words, it doesn’t have a “name” associated with it.
  • The query builder doesn’t have public access to the last selection. We can easily expose the name, but it would also match a user function named sync, which could have any return type.
  • We could try tracking more information while building the command structure from the arguments, such that if the last selection is sync, we could check if it’s from the core object types and not a user function.

It’s just simpler to skip creating sync as a sub-command when the parent object is a core type:

  • There’s less to type
  • Implementation is trivial
  • You don’t have to explain the redundancy
  • You still have access to sync. It's implicit but there's a rule and consistency to it.
  • It still allows users to define functions named sync, with totally different behavior, or even replicating the same behavior (by returning the result of sync from a core type).

After interfaces support in core types, rather than explicitly handle the current 3 core types that implement sync by name, we can generalize with the interface and keep the behavior consistent.

Drawback

If a user wants to use a function that returns a core type, and there’s a valid use case for needing the id, they need to jump through a hoop and get it wrapped in a user function that returns the result of sync (or id).

We can ignore that for now and revisit if the use case surfaces:

\cc @sipsma

Footnotes

  1. Curiously, the Python SDK has a bit of syntax sugar where you can await one of the objects directly instead of explicitly chaining sync(), for example, ctr = await src.docker_build(). ↩

Activity

  1. added
    area/cli
    on Jan 29, 2024
  2. helderco commented on Jul 5, 2024

    @helderco
    ContributorAuthor

    Just to update:

    • Some of the listed limitations no longer exist.
    • sync is no longer added implicitly since cli: print module object fields with dagger call #7479 but there's a follow up discussion about execution in CLI: don't run a container's default args when printing it #7821.
    • I think the CLI should do like the SDKs and allow sync but rather than returning the ContainerID, it should return the resulting Container with loadContainerFromID(cid).
    • With interfaces, any user module could provide the same kind of function to force execution, and with interfaces in core we can make the behavior fully generalized and not manually hardcoded to the 3 current core types.
  3. helderco commented on Jul 6, 2024

    @helderco
    ContributorAuthor

    I'm closing this in favor of:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cli

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions