swift-argument-parser icon indicating copy to clipboard operation
swift-argument-parser copied to clipboard

Implement Subcommand Autodiscovery

Open Azoy opened this issue 3 years ago • 6 comments

This is an initial draft of subcommand auto discovery using reflection to find a list of protocol conformances to ParsableCommand and looking for nested types who conform to said protocol.

I haven't added any new tests, but I've changed some of the existing tests which essentially tests this functionality. There are still tests who have subcommands who aren't nested, thus they still use the subcommand array in CommandConfiguration which allows us to test that user defined subcommands also still work. If specific tests are needed, I'll be happy to add them! This is marked WIP because there are still some more documentation needed to fully explain this feature.

Checklist

  • [x] I've added at least one test that validates that my change is working, if appropriate
  • [x] I've followed the code style of the rest of the project
  • [x] I've read the Contribution Guidelines
  • [ ] I've updated the documentation if necessary

Azoy avatar May 24 '21 16:05 Azoy

@swift-ci Please test

Azoy avatar May 24 '21 20:05 Azoy

@swift-ci Please test

Azoy avatar May 24 '21 20:05 Azoy

This is so cool!

kylemacomber avatar May 24 '21 21:05 kylemacomber

@swift-ci Please test

Azoy avatar May 25 '21 03:05 Azoy

error: unexpected platform condition (expected 'os', 'arch', or 'swift') #if _ptrauth(_arm64e)

Um, excuse me? (This has compiled in the past, and the stdlib makes use of this conditional as well??)

Edit: Seems the ci bot is using Swift 5.2.4 and this conditional wasn't released until 5.3

Azoy avatar May 25 '21 03:05 Azoy

@Azoy Did/would you consider splitting out _Runtime & _CRuntime to a separate GitHub SPM package? I'm starting to look at prototyping a dynamic loading plug-in API (https://forums.swift.org/t/swift-dynamic-loading-api/39495/21) and I think the approach you took there would be a possible nice way forward for that use case too. I was thinking of linking the plugins with that hypothetical separate package with the metadata runtime to allow for fully dynamic discovery of types conforming to the specific API protocol. It seems like generically interesting introspection capability...

hassila avatar Dec 07 '21 16:12 hassila