Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncParsableCommand never runs. Only shows help text. #662

Open
myleshyson opened this issue Sep 10, 2024 · 6 comments
Open

AsyncParsableCommand never runs. Only shows help text. #662

myleshyson opened this issue Sep 10, 2024 · 6 comments

Comments

@myleshyson
Copy link

I'm using Swift 6.0, and Im trying to use adhere to to the AsyncParsableCommand protocol. However I'm noticing that no matter what, my program always returns the help text instead of actually running.

There's post here describing this issue as well. Seems like the compiler favors the sync run command over the async run command.

Here's my main file. Just trying to print a string right now.

import ArgumentParser

@main
struct PhpFlayer: AsyncParsableCommand {
    mutating func run() async throws {
        print("I'm working!")
    }
}

ArgumentParser version: main branch
Swift version: swift-driver version: 1.113 Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1) Target: arm64-apple-macosx14.0.

Checklist

  • [x ] If possible, I've reproduced the issue using the main branch of this package
  • [x ] I've searched for existing GitHub issues

Steps to Reproduce

  1. Create an empty project
    • mkdir MyCLI && cd MyCLI
    • swift package init --name MyCLI --type executable
  2. Setup the entry file and add the argument parser package
    • Add the argument parser package to Package.swift
    • rename Sources/main.swift to Sources/MyCLI.swift
    • setup the following main struct
    import ArgumentParser
    
    @main
    struct MyCLI: AsyncParsableCommand {
        mutating func run() async throws {
            print("I'm working!")
        }
    }
  3. Run the program and see only help text show up instead of "I'm Working!"

Expected behavior

I'd expect when running swift run MyCLI that i would see "I'm working!" in the terminal.

Actual behavior

Right now this always displays the help text.

@sgade
Copy link

sgade commented Sep 12, 2024

Same with Swift 5.10. Using ParsableCommand works just fine.

@rgoldberg
Copy link
Contributor

Have you tried removing mutating?

@myleshyson
Copy link
Author

Yea. Same result unfortunately.

@rgoldberg
Copy link
Contributor

rgoldberg commented Oct 10, 2024

My code structured like the following works when running command sub. It uses Swift Argument Parser 1.5.0 on Swift 5.7.1 targeting macOS 10.15+. I do not have mutating anywhere in my code:

import ArgumentParser

@main
struct Command: AsyncParsableCommand {
    static let configuration = CommandConfiguration(
        abstract: "",
        subcommands: [
            Sub.self
        ]
    )
}

extension Command {
    struct Sub: AsyncParsableCommand {
        func run() async throws {
            try await 
        }
    }
}

@nervenes
Copy link

nervenes commented Dec 5, 2024

i have the same issue, it never runs the run function, my code looks correct - have been stuck on this for hours now. swift 6.0.2 argument parser 1.5.0

@nervenes
Copy link

nervenes commented Dec 5, 2024

ok for anyone having this problem it seems async parsable is unhappy with a package that targets a macos version below 12, so bumping the minimum platform version in Package.swift to 12+ seems to have fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants