Skip to content

module CLI commands renames - #6533

Merged
sipsma merged 6 commits into
dagger:mainfrom
sipsma:cli-renames
Feb 7, 2024
Merged

sipsma merged 6 commits into
dagger:mainfrom
sipsma:cli-renames

Conversation

@sipsma

@sipsma sipsma commented Jan 31, 2024 •

Copy link
Copy Markdown
Contributor

This implements a bare minimum subset of the polish described here and discussed separately: #6291 (comment)

Specifically, it's mainly just the stuff that's backwards incompatible, with the addition of dagger develop --sdk=... --name=... since it was trivial to support and needed as a follow-up to #6386

Changes in this PR

  • sync is renamed to develop
    • it also supports --name and --sdk flags for updating the name+sdk of a module that does not currently have those set
    • support for changing name + sdk of module with those already set will be a follow-up
  • init/install/develop/publish are all top-level commands under dagger now, not under dagger mod.
    • I left in stubs for the old dagger mod ... commands that redirect to the new command
  • dagger mod (for printing config) -> dagger config
    • no extra subcommands on dagger config yet, will bikeshed that in separate standalone PR, it just prints config information atm
  • dagger init
    • -m is not supported anymore, you can just specify an extra arg if you want to init at a path other than cwd
    • --name is optional and defaults to the name of the directory being init'd in

Follow-ups

  1. install/update/uninstall
    • add support for dagger update to update existing deps
    • change install to fail if dep at different version already exists
    • add uninstall
    • --dry-run (if worth effort in short term, otherwise can backlog)
    • consider a more explicit syntax for install, re: module CLI commands renames #6533 (comment)
      • I also think the convention suggested of doing dagger -m MOD install dep may suffice instead
  2. dagger config
    • decide on approach in terms of git config style, set/get, etc.
    • add support for setting+updating include/exclude
  3. develop
    • support renaming a module with existing name and "re-sdk'ing" a module with existing sdk

Old PR description (outdated)

Expand A few things worth detailing and/or discussing:

What to do with dagger mod?

This change currently leaves in dagger mod (no subcommands) with the same behavior as before of printing module configuration (name, sdk, source path, root path, dependencies, etc.)

This isn't awful, but I do feel a better name might be dagger config.

And at that point, I'd probably want to tweak dagger update such that:

  • dagger config - print the module configuration
  • dagger config update --name foo --sdk go - update the module configuration

I like that option the most, but holding off until I get feedback from others on this so I don't waste time 🙂

dagger update

This currently can only be used to set the name+sdk of a module that does not already have one set. E.g. this sort of use case that's possible now via #6386:

  • dagger init - create an empty nameless+sdkless module
  • dagger install github.com/foo/bar/[email protected] - add a dependency that can now be invoked with e.g. dagger call -m coolmod
  • dagger update --name mymod --sdk go - now initialize a real module with the deps from before

Attempts to update the name/sdk of a module that already has those set result in an error.

The reason for this restriction at the moment is that actually updating the module name/sdk from existing values is a bit thornier:

  • If you rename your module, in at least the go SDK you'd need to also update your code to use that name in the structs, but obviously much better would be if we did that automatically somehow
    • Need to double check if true in other SDKs @helderco @TomChv
    • One alternative option is to just accept the papercut around updating module code and print a helpful message
  • If you change your SDK, we can't translate your existing code into the new SDK lang, but it's also not clear if we should delete it (often fine, but it's scary to delete user files)

So starting out with errors in these cases made the most sense, but easy to iterate on too.

@helderco

helderco commented Jan 31, 2024 •

Copy link
Copy Markdown
Contributor

If you rename your module, in at least the go SDK you'd need to also update your code to use that name in the structs, but obviously much better would be if we did that automatically somehow

  • Need to double check if true in other SDKs

Yes, that's mostly true. Only in the Python SDK, if you use top-level functions instead of a class, then you don't need to update the code if you rename the module. The Python SDK dev module is an example of this. There's nothing in code referencing the PythonSdkDev object.

However, I've been rethinking the support for top-level functions in Python. Even though there's usually a preference for functions over classes in the ecosystem, over time we've added state in the form of object fields, constructors, main object description..., so I'm worried that users will start with functions and find the need to upgrade to a class pretty often, so I've been considering deprecating the top-level functions support.

There was a lot of pushback in the React community because the same thing happened where you could create components with either functions or classes. People preferred the simplicity of functions, but had to upgrade to a class for more "advanced" lifecycle hooks. It took some time but later they implemented hooks in a way that could be used in functions so that took care of it.

Coming back to changing code on a rename, we could make this easier if the main object wasn't named after the module, but instead be something static that the engine would then rename automatically. Same as in GraphQL you have the Query object type that's mandatory. Then this static and conventionalized class name would be handled in codegen and engine so there's less to worry about on a rename.

@helderco

Copy link
Copy Markdown
Contributor

This isn't awful, but I do feel a better name might be dagger config.

And at that point, I'd probably want to tweak dagger update such that:

  • dagger config - print the module configuration
  • dagger config update --name foo --sdk go - update the module configuration

I like that option the most, but holding off until I get feedback from others on this so I don't waste time 🙂

Yeah, I like dagger config. If we add support for the $HOME/.config/dagger.json file later, we can use dagger config --global update ....

@shykes

shykes commented Jan 31, 2024

Copy link
Copy Markdown
Contributor
  • sync is renamed to develop

👍 I think develop should also take care of initializing the SDK if needed. This way dagger develop is all you ever need to run to start developing.

Example usage scenario, starting from a codeless module:

$ dagger develop
Error: no SDK configured. Please specify one with --sdk
$ dagger develop --sdk go
Error: no module name configured. Please specify one with --name
$ dagger develop --sdk go --name mymod
Saving new SDK configuration: Go
Downloading SDK...
Building SDK...
Initializing SDK...
No source file detected. Generating template...
Generating source files...
To start developing, edit ./main.go
$ 

Then to re-generate as you develop:

$ dagger develop
Generating source files...
To start developing, edit ./main.go

You can change SDK, but it's disruptive and expected to be uncommon.

$ dagger develop --sdk python
Error: SDK is already configured. Use --force to start over with a new SDK.
$ dagger develop --sdk python --force
Saving new SDK configuration: Python
Downloading SDK...
Building SDK...
Initializing SDK...
No source file detected. Generating template...
Generating source files...
To start developing, edit ./src/main.py
  • dagger update can be used to set name+sdk of module

I think that is wrong, dagger update should be for updating installed dependencies:

dagger update [--all] [MODULE_NAME...]

I think it's best to keep configuration CRUD out of it.

Open question: does dagger update also update the SDK itself (ie, update to the latest version of the SDK), or should that be a flag in develop?

  • Option 1: dagger update [--sdk] (remaining question: does --all imply --sdk?)
  • Option 2: dagger develop [--update-sdk]
  • Option 3: a new command for sdk: dagger sdk update. But I'm trying to avoid too many subcommands if possible..

Thoughts?

What to do with dagger mod?

This change currently leaves in dagger mod (no subcommands) with the same behavior as before of printing module configuration (name, sdk, source path, root path, dependencies, etc.)

Ha, I didn't even know you could do that :)

This isn't awful, but I do feel a better name might be dagger config.

  • dagger config - print the module configuration

Yeah that's pretty good.

  • dagger config update --name foo --sdk go - update the module configuration

This is where we are going to hit the limits of CLI crud. There are going to be a bunch of fields in that config file, of various meaning and format. I don't know if mapping each top-level key to a flag will be enough - for example how do you manage root-for which is a list?

Possible options:

  • git config style. I don't remember what it is, but it exists so worth using as a baseline :)
  • Specialized map keys to subcommands:
    • dagger config: print configuration
    • dagger config set KEY VALUE: set a configuration key. Note, making KEY a subcommand makes it enumerable.
    • dagger config get KEY: print the value of a key
  • Not allow generic config crud, and use specialized commands instead, for example dagger develop --sdk to change the SDK field; dagger install to change the Dependencies field, etc. Then just have dagger info to print information about the current Dagger configuration - including the contents of your config, but also engine version, etc.

dagger update

This currently can only be used to set the name+sdk of a module that does not already have one set. E.g. this sort of use case that's possible now via #6386:

  • dagger init - create an empty nameless+sdkless module
  • dagger install github.com/foo/bar/[email protected] - add a dependency that can now be invoked with e.g. dagger call -m coolmod
  • dagger update --name mymod --sdk go - now initialize a real module with the deps from before

See above my note about using dagger develop for that.

@shykes

shykes commented Jan 31, 2024

Copy link
Copy Markdown
Contributor

We're also going to need:

  • dagger uninstall (not urgent, but should fit in the model)
  • A way to check for available versions of dependencies without actually installing them - --dry-run for install and update?
  • A command for managing root-for. How will that work?

@sipsma

sipsma commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

Note from Nipuna about another adjustment I think we should consider to dagger install syntax: https://discord.com/channels/707636530424053791/1202734818358595635/1202735318403645480

He was in a dir for module A and wanted to install ../b and ../c and ran the command dagger mod install -m ../b ../c, reasonably intuiting that would mean "install ../b and ../c to the current module directory".

But the syntax actually meant "install ../c to module ../b", with -m ../b meaning "install to module at ../b and the trailing ../c being the module to install.

He suggested having more explicit flags here like:

dagger mod install --source a --target b

The exact name of the flags is worth bikeshedding, but I fully agree that more explicit flags here would result in more obvious syntax.


Just adding as a comment here in case it makes sense to tackle. Otherwise will spin out to separate issue.

@sipsma

sipsma commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

From @shykes, we should retire --workdir since it's mostly redundant with -m for module commands now.

I think at the very minimum it should not be a top-level flag on dagger and only be used by some of the older subcommands like listen, the hidden SDK util session command, etc. But maybe even those no longer need it.

@helderco

helderco commented Feb 1, 2024

Copy link
Copy Markdown
Contributor

I have a few items for a follow up left from (see Todo):

I've been changing PersistentFlags to Flags a lot these past few days. Just because of all the rebases/new/changed flags and just giving priority to other things like text wrapping so never commiting. But I did start experimenting with removing "Global Flags" from --help.

For TUI and module flags, once the flags are parsed there's no sense continuing to have them available on sub-commands. It's too late to apply. Most of the others could be shown only on the root dagger help command. Some also on top-level commands, but no further.

@shykes

shykes commented Feb 2, 2024

Copy link
Copy Markdown
Contributor

For TUI and module flags, once the flags are parsed there's no sense continuing to have them available on sub-commands. It's too late to apply. Most of the others could be shown only on the root dagger help command. Some also on top-level commands, but no further.

I like that!

@sipsma

sipsma commented Feb 2, 2024 •

Copy link
Copy Markdown
Contributor Author

👍 I think develop should also take care of initializing the SDK if needed. This way dagger develop is all you ever need to run to start developing.

Yep that makes sense to me. My only source of hesitation was that there's a lot of fields in dagger.json and it's not always clear which command is for updating which field. But I think the idea could be that:

  • modifying any settings that involve module references gets it's own specialized subcommand
    • e.g. dagger install (modifies dep mod refs), dagger develop (modifies sdk mod refs)
  • all other settings get bucketed into dagger config
    • e.g. include, exclude, root-for

I think that is wrong, dagger update should be for updating installed dependencies:

Just for context, updating deps today looks like e.g.:

  1. Install new dep not already present: run dagger mod install github.com/foo/bar/depmod
    • This results in github.com/foo/bar/depmod@<latest commit> being newly added to your list of dependencies
  2. Later, you want to update to the latest commit: run dagger mod install github.com/foo/bar/depmod
    • The engine knows that you already have a different version of depmod in your dependencies so it replaces the old entry with github.com/foo/bar/depmod@<new latest commit>

The above works when specifying @<tag/commit/etc.> too, the idea being that the engine will always replace an existing different version of the dep with the one specified in install.

I do like having a separate command for this though since it would be much more explicit and obvious in many ways. And also agree that we'd then want dagger update to be for that rather than updating arbitrary config (which can instead be bucketed in dagger config in one form or another)

In this new model, I think it would make sense for dagger install to now fail if you try to install a dep that is already present at a different version. Just double checking others agree too.


On a high-level note: I'm going to update this PR to just contain the things that seem clear in terms of consensus and split out some of the thornier parts to separate follow-ups (will make issues). That'll unblock parallelizing those efforts.

Updating it to have just:

  • mod init/install moved to top-level
  • sync -> develop and support for dagger develop --sdk=... --name=...
  • dagger mod (for printing config) -> dagger config
    • no extra subcommands on dagger config yet, will bikeshed that in separate standalone PR

Follow-ups:

  1. install/update/uninstall
    • add support for dagger update to update existing deps
    • change install to fail if dep at different version already exists
    • add uninstall
    • --dry-run (if worth effort in short term, otherwise can backlog)
    • consider a more explicit syntax for install, re: module CLI commands renames #6533 (comment)
  2. dagger config
    • decide on approach in terms of git config style, set/get, etc.
    • add support for setting+updating include/exclude

cc @shykes @helderco

@nipuna-perera

Copy link
Copy Markdown
Contributor

Attempts to update the name/sdk of a module that already has those set result in an error.

While developing modules I find myself renaming them occasionally. It would be great to have at least basic support for it. I am happy even if it comes with a warning. It would be great if dagger can identify local dependent modules and update their references also but I understand that may be to complicated/error prone.

@sipsma
sipsma force-pushed the cli-renames branch 2 times, most recently from 4eda39f to dcd0877 Compare February 2, 2024 23:29
@sipsma sipsma added this to the v0.9.9 milestone Feb 5, 2024
@sipsma
sipsma force-pushed the cli-renames branch 4 times, most recently from 6a7c093 to 27200e9 Compare February 5, 2024 20:17
@sipsma sipsma changed the title module CLI commands polish module CLI commands renames Feb 5, 2024

@shykes shykes left a comment

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.

Playing with this build live (using Zed for the first time, yay!):

Focusing on dagger init:

  1. dagger init -m feels confusing. I think we should cut it, and later when/if -m becomes a global flag like we discussed, then it will apply equally to all subcommands.

  2. dagger init [PATH] would be a nice addition, especially combined with a default value for --name. dagger init foo is nicer to type than mkdir foo && cd foo && dagger init --name foo

  3. dagger init should not have --sdk at all. The idea is that init becomes much more lightweight: just add a dagger.json. Later if you want to add code to your module, you develop functions with dagger develop

@sipsma

sipsma commented Feb 5, 2024 •

Copy link
Copy Markdown
Contributor Author
  1. dagger init -m feels confusing. I think we should cut it, and later when/if -m becomes a global flag like we discussed, then it will apply equally to all subcommands.
  2. dagger init [PATH] would be a nice addition, especially combined with a default value for --name. dagger init foo is nicer to type than mkdir foo && cd foo && dagger init --name foo

Yeah I can see how -m is confusing for init. Agree that [PATH] would be much clearer, will update 👍

EDIT: pushed those changes, no -m on dagger init and dagger init --name defaults to name of the source root dir

  1. dagger init should not have --sdk at all. The idea is that init becomes much more lightweight: just add a dagger.json. Later if you want to add code to your module, you develop functions with dagger develop

@shykes I feel like this just results in extra boilerplate in that if you want to init a module and develop on code right away you have to do two commands: dagger init and then dagger develop --sdk=go --name=foo. Obviously if that's not what you want to do you are free to dagger init (no flags) and then maybe do dagger develop later if you want.

But what's the harm in supporting dagger init --sdk=go --name=foo as a shortcut for when you want to start out with an sdk+name right away? I don't really see any right now.

This also required a slight implementation adjustment to give
re-configuring an SDK the same behavior as re-configuring a name in that
it only becomes an error once you try to re-generate the source code.
This allows custom SDKs to re-use other SDKs more easily, which is
relied on for our custom SDK test.

Signed-off-by: Erik Sipsma <[email protected]>
@shykes

shykes commented Feb 7, 2024

Copy link
Copy Markdown
Contributor
  1. dagger init should not have --sdk at all. The idea is that init becomes much more lightweight: just add a dagger.json. Later if you want to add code to your module, you develop functions with dagger develop

@shykes I feel like this just results in extra boilerplate in that if you want to init a module and develop on code right away you have to do two commands: dagger init and then dagger develop --sdk=go --name=foo. Obviously if that's not what you want to do you are free to dagger init (no flags) and then maybe do dagger develop later if you want.

But what's the harm in supporting dagger init --sdk=go --name=foo as a shortcut for when you want to start out with an sdk+name right away? I don't really see any right now.

I see what you mean.

The harm (big word but I'll run with it :) would come from making it slightly harder to understand the purpose of each command, because init does more things and has more flags, and there are two ways to achieve the same thing.

Not worth holding back merge though.

@sipsma

sipsma commented Feb 7, 2024

Copy link
Copy Markdown
Contributor Author

The harm (big word but I'll run with it :) would come from making it slightly harder to understand the purpose of each command, because init does more things and has more flags, and there are two ways to achieve the same thing.

Not worth holding back merge though.

@shykes Yeah that's true too. My gut feeling is that the cost of having --sdk on both init and develop is less than the cost of forcing users to always run two commands in the case where the know what sdk they want. I think it's pretty straightforward to explain what --sdk does in both cases. But very much splitting hairs.

I'll just leave it as is for now until I hear other opinions (cc @helderco or anyone who wants to be a tie-breaker here 😄).

@shykes shykes left a comment

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.

Let's merge and keep talking in follow-ups :)

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.

4 participants