yonaskolb / Beak

A command line interface for your Swift scripts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please add shebang support

twostraws opened this issue · comments

Unix scripts frequently start with a shebang/hashbang line like #!/bin/bash or #!/usr/bin/env python, which allows the rest of the script to be executed using a specific program.

This seems perfect for Beak: if I could use Beak in the shebang line then I could move hello.swift directly into /usr/local/bin/hello and run it using a command such as hello run release.

This would probably require moving the --path param to before the subcommand, so an interpreter could easily parse the remaining arguments.

A simple shell script could then put placed somewhere which makes a beak call and passes the file as the --path. You could then reference that script in the shebang #!/usr/local/bin/beak-command

Is that what you mean? What support from beak would you want? An automatically installed interpreter?

Perhaps it's easier if I give a complete example. What I want is to be able to create a file like this:

#!/usr/bin/env beak

/// Releases the product
/// - Parameters:
///   - version: the version to release
public func release(version: String) throws {
    // implementation here
    print("version \(version) released!")
}

/// Installs the product
public func install() throws {
    // implementation here
    print("installed")
}

…then move that to /usr/local/bin/myapp, chmod a+x it, then run myapp run install. That would tell Beak "consider the rest of this as file your input, now please run its install() method."

Yep, I understand. Now that I've moved the --path argument before the subcommand in master, you can simply adding this shebang #!/usr/bin/env beak --path.

Resolved in 0.3.0. Let me know if you have any issues