Using an OptionGroup and invoking a ParseableCommand as a client of a CLI library

Hi, I’m trying to figure out the best way to handle a use case where we have an argument parser that can be used as a library, such that a client can define a command that makes use of the library commands via the standard ParseableCommand functions. We want to avoid making the command properties part of the library API by making them public.

Supposing this:

  • The library defines some set of arguments struct LibraryFlage: ParsableArguments
  • The library defines LibraryCommand: AsyncParseableCommand that defines @OptionGroup var libraryFlags: LibraryFlags

I want to use this library in my code and define MyCommand that parses the same LibraryFlags as LibraryCommand, does some custom work, and then invokes LibraryCommand.

Is there a clean way to do this without breaking encapsulation on LibraryCommand?

It seems like we could craft a public method like LibraryFlags.args() -> [String] that MyCommand would invoke to build an arg list to use with LibraryCommand.parse() but is fussy from a maintenance and validation perspective.

MyCommand could use class inheritance I suppose but that feels somewhat dirty.

Is there a better approach?