Skip to content

CLI: print module object fields with dagger call #6515

Closed

Description

@helderco

Problem

When dagger call ends on an object (as opposed to a scalar value), it returns an error with a message saying "please query a field of this object".

This is a problem because:

  1. At a glance, it gives the impression that the user did something wrong, when in fact they did not. So an error is sending the wrong message.
  2. It makes a valid task (produce an object and look at it) harder than it should be. Just show me the object!

Solution

  1. Never show an error when a function has successfully be called, and has returned an object
  2. Print the contents of the object in a useful format

There are two options for what to print:

Option 1: call all scalar functions

In this option, we call all functions in the object that return a scalar value, and print the result, either in JSON, YAML or pretty-print format (configurable by a flag). Possibly excluding the ID by default (also configurable).

On the question of "expensive scalar functions: for example, Container.stdout() is "expensive" because it forces actually executing a container, in order to retrieve its standard output. Therefore, it is argued, the CLI should not blindly call all scalar functions of an object, because it may cause expensive computation which the user does not want. This is premature optimization. Let's ship the feature in a naive implementation; then see how important it actually is to avoid expensive computation. My guess is that, in most cases, it won't matter. For example, if I query a container, I don't care that it's actually executed. Or, if it turns out it's a problem, then we can implement a special case in the core type. I certainly won't care if my own custom types don't benefit from such a special case.

Pre-requisites

As a prerequisite, we need:

Option 2: print list of all functions

In this option, we don't call any functions. Instead, we print a list of them, possibly with a description. Again, this could be either pretty-printed, or exported to json or yaml.

In this scenario, dagger call becomes the simplest way to discover available functions. This in turn would allow simplifying dagger call --help, which is quite noisy. --help would no longer need to print all functions of the return types: it could focus on printing available arguments. This solves a common problem, especially for functions that return core types like Container or Directory, which have many functions - these tend to drown out the flags.

Activity

  1. added
    area/cli
    on Jan 29, 2024
  2. shykes commented on Mar 27, 2024

    @shykes
    Contributor

    @helderco are you thinking we should print the values of the fields, or just their names?

    I initially thought the former (show value of all scalar fields). But now I'm thinking that simply printing the name of all fields, would be easier and actually more useful.

  3. shykes commented on Mar 27, 2024

    @shykes
    Contributor
  4. helderco commented on Mar 27, 2024

    @helderco
    ContributorAuthor

    @helderco are you thinking we should print the values of the fields, or just their names?

    I was thinking both name and values.

    I initially thought the former (show value of all scalar fields). But now I'm thinking that simply printing the name of all fields, would be easier and actually more useful.

    So if a function returns a Container type, you suggest printing these?

    ❯ dagger -m github.com/helderco/daggerverse/[email protected] call introspect get-type --name=Container simple-leafs name
    imageRef
    platform
    stderr
    stdout
    user
    workdir
  5. shykes commented on Mar 27, 2024

    @shykes
    Contributor

    I was thinking both name and values.

    Right, name+values of scalar fields only? (what I meant).

    So if a function returns a Container type, you suggest printing these?

    ❯ dagger -m github.com/helderco/daggerverse/[email protected] call introspect get-type --name=Container simple-leafs name
    imageRef
    platform
    stderr
    stdout
    user
    workdir
    

    I guess there are quite a few more; but yes that is the other option I'm considering. Possibly with description too.

    In this scenario, dagger call <PATH_TO_OBJECT> would simply replace dagger call <PATH_TO_OBJECT> --help. Maybe that would allow us to remove that contents from --help, and only show flags. It's a common problem I run into, that I call --help for a function that returns a container, and have to scroll up past the many follow-up functions, to find the flags.

  6. shykes commented on Mar 27, 2024

    @shykes
    Contributor

    @helderco I edited the issue description, to add more context + describe the two available options.

  7. helderco commented on Mar 27, 2024

    @helderco
    ContributorAuthor

    I guess there are quite a few more;

    Not really. Those are all the Container fields that return a non-id scalar (excludes id and sync), and that have no required arguments. Fields that return lists aren't included too. Internally those return a list of IDs.

    I kind of like the idea of showing available functions and clean up --help a bit more. And with #6949 you'll be able to explicitly select multiple fields instead of implicitly for all scalars.

  8. self-assigned this
    on May 17, 2024
  9. helderco commented on May 21, 2024

    @helderco
    ContributorAuthor

    I think Option 2 works best. See:

    Rationale

    • Hard to generalize a way to print all sorts of types, especially considering multiline values.
    • Listing provides a nice flow where you don’t need to reach for dagger functions or add --help to continue chaining. Felt really nice when I used it in a few cases.
    • Listing works every time, even with core api (dagger -m- call), but there may not be any functions returning scalars (and no arguments) to show anything up for.
    • Doing CLI: allow querying multiple fields in the same object #6949 makes it explicit which takes some of the guesswork out of it, while also enabling a new feature (concurrency). It also avoids having to probably hard code the fields for a few core types for a better user experience if it were auto-discovered.
    • I think people would probably ask us to control which functions get printed for an object at one point.
  10. helderco commented on May 21, 2024

    @helderco
    ContributorAuthor

    One question remains about arguments.

    It's nice that you get a list of functions to continue chaining, but while that chaining is being built you also need to add the available arguments, or at least the required ones if they exist. Otherwise you'll still need to resort to --help a lot for that, but worse is adding the next command in the chain, only to fail on a missed required argument. At that point you need to replace the last command with --help.

  11. shykes commented on May 24, 2024

    @shykes
    Contributor

    Cross-posting my comment from #7421: I prefer option 1.

    I understand the desire for a better discovery flow, --help is not ideal. But when I type dagger call FUNC, I expect FUNC to be... called.

  12. helderco commented on May 24, 2024

    @helderco
    ContributorAuthor

    Ok, I can work on the alternative and then we can see the difference in practice. I actually started with that and already unblocked the pre-requirement in Go's query builder to support it (demoed it last week). Just found the listing experience nicer and easier to be consistent with.

    I have a few issues with printing the fields. Expensive functions for one, but also that it doesn’t completely solve the "object requires a sub-selection" error. It just replaces it with a "nothing to print" kind of message in a lot of cases. I wonder if you're thinking too narrowly about the use cases here.

    However, I do see the potential when that output is actually useful. And I also see your arguments about discovery being better as something separate; premature optimization; and that most users may end up preferring this solution. But we won’t really know if we don’t put it out there and get feedback. 🙂

    So... my gut wants to limit selecting only state functions (fields) rather than all functions, and maybe hardcode which ones in a few core types. Would you rather consider all functions equally instead, @shykes?

  13. helderco commented on May 25, 2024

    @helderco
    ContributorAuthor

    Wdyt about listing available functions when there's no scalars to print?

  14. shykes commented on May 28, 2024

    @shykes
    Contributor

    FYI I haven't forgotten about this, it's a tough one 😭

  15. removed
    area/cli
    on May 31, 2024
  16. helderco commented on May 31, 2024

    @helderco
    ContributorAuthor

    Latest iteration just adds a _type field to the response to make sure something is always returned. No listing anymore.

  17. added
    area/cli
    and removed on Jun 4, 2024
  18. shykes commented on Jun 28, 2024

    @shykes
    Contributor

    Thank you !!! Can't wait to use this

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

Metadata

Metadata

Assignees

Labels

area/cli

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions