-
Notifications
You must be signed in to change notification settings - Fork 481
Expose Command Structs for Plugins #603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose Command Structs for Plugins #603
Conversation
@jglogan This also accomplishes some of the work that I found necessary when developing my initial compose effort, because it increases safety and reduces the developer workload to reproduce, funnel, or output commands being run in the background. It also will encourage devs to use the commands internal to container instead of modifying containers and other things directly. |
How are you running the commands? Are you using ParseableCommand.parse()? |
You can do that, or just init it and then manually set every property after it. Because of how Swift parser operates, we can't just init it with all of the properties, so we have to instead init it empty and then set all of the properties. An example of this is in my Compose proposal. |
Having the ParseableCommand types public so we can all import the library and use parse() totally makes sense. I'd prefer that that be just the API, instead of making it so that any change to the member properties is potentially a breaking change. Could we start with this PR simply allowing clients to use parse(), without changing member visibility? |
@jglogan We could put that in the documentation, but |
However, we could make all properties and functions private to force use of the parse method. |
Exactly! Could you try that approach - making the CLI library such that you can import it and use parse, but the property visibility isn't public? I'm curious how that'd work for your plugin. |
Also, do you have an enhancement issue open for making the CLI library importable? If not, please create one and I'll assign it to you. It'd be best to have an issue backing each PR (especially for larger changes or those affecting the API). Thanks! |
I didn't have one, so I just made #609. But as I try to update my Compose plugin to use entirely parse, it is becoming increasingly difficult to pass down global flags that I want to respect inherently such as I strongly think that a great DX is the only way that people will make plugins for If we do the latter, this would not be required because |
@jglogan We can undo it, but I decided to go ahead and make all of the OptionGroup properties public to make this possible. Again these are not required to be set when using |
Actually, before we merge this, should I update the readme with information about developing plugins? |
Nah, for that, could you create a git issue for plugin development information? You and I can put together an outline there first, and then we'll do that in a dedicated PR. It's long overdue. I have some thoughts scratched down in a local branch but have been getting sidetracked a lot. |
Builds now! I went through everything and left a few comments regarding some of the private methods that went to default visibility. Was that needed to compile the code without errors? For those (especially the table output stuff which we should just solve in a better way), I'm inclined to leave these private until someone actually needs to use these functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the files System/Property/*.swift should get the same treatment.
Sounds good. I will fix these soon |
@Mcrich23 Do you have an example of a plugin you're hoping to use these changes with? Draft code is fine, I'm just curious to see how it looks |
@katiewasnothere yeah. This hasn't been updated entirely for the finalized interface, but it and the conversation here should give you a decent idea of the current API with ContainerCommands. https://github.com/Mcrich23/container/blob/add-compose/Plugins/Compose/ComposeCLI/Commands/ComposeUp.swift |
import ContainerCommands | ||
|
||
@main | ||
public struct Executable: AsyncParsableCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sufficiently dumb, but what is this target for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new compose executable entry point since I could not otherwise get an executable and normal target for the same sources. So this is just a proxy making it executable.
Looks like we need |
commit dd6bdc2 Author: Morris Richman <[email protected]> Date: Wed Sep 17 15:24:26 2025 -0700 Expose Command Structs for Plugins (apple#603) ## Type of Change - [ ] Bug fix - [x] New feature - [ ] Breaking change - [ ] Documentation update ## Motivation and Context Plugins technically exist, but to add shortcuts or to do existing things with functions in `container` requires calling a compiled binary. This pull request aims to remove that hurdle and instability by exposing commands as a new `ContainerCommands ` target. Simply import `ContainerCommands` and you can access almost any command as if it were a native part of the binary. This makes plugin development significantly easier. Closes apple#609.
## Motivation and Context This is an extension of #603 to cleanup the folder structure and have it match with the new library and target names.
Type of Change
Motivation and Context
Plugins technically exist, but to add shortcuts or to do existing things with functions in
container
requires calling a compiled binary. This pull request aims to remove that hurdle and instability by exposing commands as a newContainerCLI
target.Simply import
ContainerCLI
and you can access almost any command as if it were a native part of the binary. This makes plugin development significantly easier.Testing