kiliankoe / swift-outdated

A swift subcommand for displaying when your dependencies (SwiftPM or Xcode) are out of date
MIT License
342 stars 14 forks source link

Support running outdated command from swift #37

Closed martin-muller closed 1 year ago

martin-muller commented 1 year ago

Hi @kiliankoe, thank you for this great library! We're using your library by running the command directly from our spm executable, we previously raised https://github.com/kiliankoe/swift-outdated/issues/31 but we forgot to compile our executable so we didn't realise the fix you did won't support our use case.

I've outlined the changes we would need in the pr. We depend on the outdated product and import it in our command like this:

import ArgumentParser
import Foundation
import Outdated

struct Outdated: AsyncParsableCommand {
    static var configuration = CommandConfiguration(
        commandName: "outdated",
        abstract: "Prints outdated swift packages."
    )

    func run() async throws {
        printHeader("Outdated")

        let outdated = SwiftOutdated.self
        let command = outdated.parseOrExit(["-f", "markdown"])
        try await command.run()
    }
}

We then compile an executable containing all subcommands we use in our day-to-day work, which allows the whole team to quickly run commands on the same version.

Is this a use case you would support?

kiliankoe commented 1 year ago

Hey @martin-muller! Huge thanks for the PR. Looking over this I don't really want to move the command itself into the library target however. I really don't want dependents of the library having to integrate the arg parser into their project as well, it's nice to keep that separate.

I have another suggestion which should result in something similar for you guys. Would you mind having a look at #38?

For your usage this would result in changing your example from this:

let outdated = SwiftOutdated.self
let command = outdated.parseOrExit(["-f", "markdown"])
try await command.run()

to this:

let pins = try SwiftPackage.currentPackagePins(in: .current) // or whatever directory
let packages = await SwiftPackage.collectVersions(for: pins, ignoringPrerelease: false)
packages.output(format: .markdown)

Would this also work for you? It's also totally possible I misunderstood your intention here entirely 😅

martin-muller commented 1 year ago

Thank you for looking into this, this is much nicer than what I'm proposing, exposing the api makes more sense than running the command directly and it makes it much easier for us to merge results from swift-outdated and pod outdated which is great!

I'm just wondering if there is a way to silence the logging? Happy to open separate issue/pr if you prefer

kiliankoe commented 1 year ago

Thanks for the feedback! I'm going to go ahead and merge my change then.

For the logging I'd prefer a separate issue, what's going on there? 😬

kiliankoe commented 1 year ago

closing this in favor of #38