Repository navigation
Description
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:
- 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.
- It makes a valid task (produce an object and look at it) harder than it should be. Just show me the object!
Solution
- Never show an error when a function has successfully be called, and has returned an object
- 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
shykes commentedon Mar 27, 2024
@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.
shykes commentedon Mar 27, 2024
FYI @grouville
helderco commentedon Mar 27, 2024
I was thinking both name and values.
So if a function returns a
Containertype, you suggest printing these?shykes commentedon Mar 27, 2024
Right, name+values of scalar fields only? (what I meant).
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 replacedagger 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--helpfor a function that returns a container, and have to scroll up past the many follow-up functions, to find the flags.shykes commentedon Mar 27, 2024
@helderco I edited the issue description, to add more context + describe the two available options.
helderco commentedon Mar 27, 2024
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
--helpa bit more. And with #6949 you'll be able to explicitly select multiple fields instead of implicitly for all scalars.helderco commentedon May 21, 2024
I think Option 2 works best. See:
Rationale
dagger functionsor add--helpto continue chaining. Felt really nice when I used it in a few cases.dagger -m- call), but there may not be any functions returning scalars (and no arguments) to show anything up for.helderco commentedon May 21, 2024
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
--helpa 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.shykes commentedon May 24, 2024
Cross-posting my comment from #7421: I prefer option 1.
I understand the desire for a better discovery flow,
--helpis not ideal. But when I type dagger call FUNC, I expect FUNC to be... called.helderco commentedon May 24, 2024
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?
helderco commentedon May 25, 2024
Wdyt about listing available functions when there's no scalars to print?
shykes commentedon May 28, 2024
FYI I haven't forgotten about this, it's a tough one 😭
helderco commentedon May 31, 2024
Latest iteration just adds a
_typefield to the response to make sure something is always returned. No listing anymore.shykes commentedon Jun 28, 2024
Thank you !!! Can't wait to use this