Use spf13/cobra for the cli#22769
Conversation
There was a problem hiding this comment.
It feels a little weird to me that the struct is called CobraAdaptor but the package name is cobradaptor (one fewer a). I don't have anything against the portmanteau but I'd rather not have two confusingly similar names.
There was a problem hiding this comment.
Fair enough, I'll make these consistent
|
Does it also get rid of the reflection that ends up leaving the code oddly disconnected? |
|
Reflection is already gone :) |
|
A few tests are breaking because Personally that behaviour feels wrong. Do we want to continue to support that quote trimming? |
|
@LK4D4 really? What other CLI removes quotes from the middle of an argument? Normally the shell strips them off for you, but I don't think the application does anything with them. |
|
@dnephin yeah, maybe it's shell |
|
I had a quick look at some features cobra offers, and it looks pretty neat. We may want to look into the auto-generation of man-pages and completion scripts if this is accepted, so "+1" from me |
|
Design is OK for me. |
|
@dnephin I think it's okay to start to work on rebase and CI issues. |
5c6ddac to
7f5732c
Compare
|
ping @docker/core-engine-maintainers PTAL |
Signed-off-by: Daniel Nephin <[email protected]>
Signed-off-by: Daniel Nephin <[email protected]>
Signed-off-by: Daniel Nephin <[email protected]>
|
@dnephin I gotta ask about something really odd with the old cli. If someone typed: it would do some really weird parsing and connect the btw - I say its weird because normally I don't think parsers do that. For example: |
|
@GordonTheTurtle died, so stay tuned while we're figuring that out, so don't merge before it's back |
|
@thaJeztah just pushed a commit that marks |
|
@dnephin thanks! I'll give it a spin locally |
|
@duglin I think that behavior comes from the pflags library, and they should be compatible, but I haven't tested it. |
|
@duglin hmm, I haven't encountered that yet, and I don't know if that works with cobra and pflags. Note this only converts the Let me experiment and see how that works. |
|
ah that would explain why it still parses in that weird way :-) |
|
actually, if this just moves over "volume" I'd prefer if we did some other command (like "run") too because if we encounter something really nasty that would prevent us from migrating all commands then I'm not sure we should move over just some of them. |
|
I agree with @duglin . Run and would be great tests to see what can be broken. |
|
One known "limitation" (which is really by design) is that the very old flags that use single dash but multi character ( I can start working on a PR to convert run, but it would be nice to keep it as a separate PR as this is already quite large. I don't think we'll encounter any serious problems, we can always patch cobra/pflags to do what we need them to do. |
|
@dnephin I think all single-dash flags have been removed https://github.com/docker/docker/blob/master/docs/deprecated.md#old-command-line-options |
|
I'm going to create a separate PR to show |
- adds support for usage strings on flag errors - adds support for arg validation Signed-off-by: Daniel Nephin <[email protected]>
Signed-off-by: Daniel Nephin <[email protected]>
Also re-use context. Signed-off-by: Daniel Nephin <[email protected]>
Signed-off-by: Daniel Nephin <[email protected]>
|
@duglin I think the weird behavior of |
|
LGTM |

https://github.com/spf13/cobra is a widely used framework for creating clis. I believe migrating to this framework comes with many advantages:
docker imagesanddocker image lscould exist by callingaddCommand()on two different commands).What I did
api/client/inspectso that it can be used from multiple packages. This is necessary because with cobra the commands are in different packages, not a single package.CobraAdaptorthat acts as an adaptor between the existing docker cli command delegation and the cobra command delegation. This allows us to migrate a few commands at a time, instead of doing it all in a single massive PR.DockerClias a data object, and exposeOut(),Err()andClient()so they can be used from separate packages.volumecommands to use cobra commands.