apple / swift-argument-parser

Straightforward, type-safe argument parsing for Swift
Apache License 2.0
3.31k stars 311 forks source link

Automatic versioning handling through SwiftPM plugin #567

Open kiliankoe opened 1 year ago

kiliankoe commented 1 year ago

Hi,

it's always felt a bit weird to me to have to manually hardcode and maintain the version number as part of my main command, e.g.

@main
struct Command: ParsableCommand {
    static let configuration = CommandConfiguration(
        // ...
        version: "1.0.0",
        // ...
    )
}

I'd typically have my version stored in git tags and the string here and it's a (admittedly) minor pain if I forget to update the version in code and only update the tag.

Swift Package Manager plugins now offer the ability of generating code at compile-time and thus also generate this version information based on the available git repo metadata. There are some packages that already that do just that (see for example here, here, and here). It would be great however to have such a plugin built directly into and distributed as part of swift-argument-parser so that I could optionally automatically reference a version string pulled from my git repo there.

Thanks for considering!

natecook1000 commented 1 year ago

Hi @kiliankoe, thanks for the suggestion! It seems like there are so many different ways of managing version numbers that it would be hard to provide all that flexibility in this particular package. From what I can see, all three of those plugins that you referenced would integrate well with ArgumentParser's CommandConfiguration.version setting, but each one uses a different way of generating and surfacing the package/project metadata! I think having other package supply that information is probably the right situation right now.

If you have a proposed design or more information about a standard way of providing versioning information, I'd be happy to discuss further!