Code Monkey home page Code Monkey logo

beak's People

Contributors

jakeheis avatar maxchuquimia avatar tflhyl avatar vknabel avatar yonaskolb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beak's Issues

Please add shebang support

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.

Add edit command

beak edit
This would allow code completion for dependencies.

  • generate package like for run but without injected function call, rather use a symlink to the original swift file
  • generate the project with Swift PM
  • open the project

`Illegal instruction: 4` when running beak commands

Hi, I just wrote me a script to update a spreadsheet on a vocabulary learning site. I edited the file within Xcode by running beak edit, but the problem is that after writing some code the commands beak edit, beak list and beak run all didn't work.

As a workaround what I'm doing right now is to comment out all code below the import statements with an editor like Atom, then I run beak edit (which then works fine) and then I uncomment the lines again in Xcode. When I run the Beakfile scheme within Xcode everything just works fine, so I can somehow use the script. But I would rather use things as designed: from the command line. :)

Here's the entire content of my beak.swift file:
https://gist.github.com/Dschee/3c4b89ef9da39ab7714c47fa97dc4cae

And this is the error I get when running any beak commands:

Illegal instruction: 4

I'm using beak 0.3.1 on macOS 10.13.3 with Xcode 9.2.

Any ideas why this happens? The error code doesn't really help ...

Does not pass interrupts to running script

A fix was previously attempted in #20, but stalled by SwiftShell deficiency. It's now possible with SwiftShell (kareman/SwiftShell#61) or SwiftCLI. I'm happy to work on whichever implementation you'd prefer -- SwiftShell would obviously involve less changes, but I know you mentioned at one point a desire to remove the dependency on SwiftShell if possible.

Error on installation

Hi i'm trying to install beak using swift run beak run install but i got this error:

error: root manifest not found
⚠️  Command '/bin/bash -c "swift build --disable-sandbox"' returned with error code 1.

This is my swift --version:

Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.5.0

Any idea?

Add a way of including local dependencies

I'm experimenting with beak to automate some tasks and it's been a great experience so far. Thank you for creating this great tool! It's well documented and delivers what it promises.

Currently beak supports dependencies with // beak: {repo} {library} {library} ... @ {version} syntax. I'm wondering if this syntax / dependency handling could be enhanced to enable local package dependencies.

To me it feels like a single beak.swift file can become bloated if one wants to utilise this great tool for many tasks. In order to split some project specific solutions for different problems, I would love the ability for beak to include from a local package. This could follow SPM dependency format for local dependencies. E.g.:

// beak.swift

// - github
// beak: kareman/SwiftShell @ 4.0.0
// - local
// beak: ../MyTasks

import SwiftShell
import MyTasks

I don't know if this aligns with the philosophy of beak, but I think this could be very useful.

Installation via Homebrew fails

Currently the installation of beak via Homebrew fails. This was reported to me, so I removed beak from Homebrew and got the same error (and can't use Beak anymore myself 😭 ):

==> Installing beak from yonaskolb/beak
==> Downloading https://github.com/yonaskolb/Beak/archive/0.3.2.tar.gz
Already downloaded: /Users/Cihat/Library/Caches/Homebrew/beak-0.3.2.tar.gz
==> Building Beak
==> swift build --disable-sandbox -c release -Xswiftc -static-stdlib
Last 15 lines from /Users/Cihat/Library/Logs/Homebrew/beak/01.swift:
error: product dependency 'Utility' not found
error: product dependency 'SwiftShell' not found
error: product dependency 'Spectre' not found
error: product dependency 'PathKit' not found
Fetching https://github.com/jpsim/SourceKitten
Fetching https://github.com/kylef/PathKit.git
Fetching https://github.com/kylef/Spectre.git
Fetching https://github.com/yonaskolb/swift-package-manager
Fetching https://github.com/kareman/SwiftShell.git
Fetching https://github.com/drmohundro/SWXMLHash.git
Fetching https://github.com/jpsim/Yams.git
Fetching https://github.com/norio-nomura/Clang_C.git
Fetching https://github.com/Carthage/Commandant.git
Fetching https://github.com/antitypical/Result.git
Fetching https://github.com/norio-nomura/SourceKit.git

If reporting this issue please do so to (not Homebrew/brew or Homebrew/core):
yonaskolb/beak

/usr/local/Homebrew/Library/Homebrew/utils/github.rb:220:in `raise_api_error': curl failed!  (GitHub::Error)
curl: (22) The requested URL returned error: 422 Unprocessable Entity
curl: (3) <url> malformed
	from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:178:in `open'
	from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:278:in `search'
	from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:225:in `search_issues'
	from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:238:in `issues_for_formula'
	from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:369:in `fetch_issues'
	from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:365:in `issues'
	from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:419:in `dump'
	from /usr/local/Homebrew/Library/Homebrew/brew.rb:138:in `rescue in <main>'
	from /usr/local/Homebrew/Library/Homebrew/brew.rb:30:in `<main>'

Add support for including other Swift files

Some of my beak.swift files became quite long recently and I fell like I'd rather split them into separate files with separate contexts. I'm not sure if this is possible at the moment somehow, but I couldn't find something. What I'm thinking of is something like this:

// include: beakScripts/DependencyManagement.swift
// include: beakScripts/ProjectInitializer.swift
// include: beakScripts/Utility.swift

This way one could keep the beak.swift file small and only import dependencies that are needed in the smaller files. Internally, Beak could simply replace the above entries with the files contents and build the result only reordering the dependency declarations to the top (if needed, I'm not sure if they can be declared somewhere down the line). So this should not be too hard to implement.

Alternatively the following could also be possible to include all Swift files in a directory:

// include: beakScripts

Positional params for unnamed params

This would support unnamed params in Swift functions and allow you to pass positional parameters

func release(_ version: String) {
}
beak run release 1.2.0

There's an argument to be made that all required params could use position params

Position in this case means arguments with no labels (--version 1.2.0 vs 1.2.0)

Install command

Add an install command which would bundle up your script and make it globally available

Make Beak available via Homebrew Core

Currently, when trying to install this simply via brew install beak it doesn't work due to a custom tap needed. While this is not much additional work (so could be seen as "OK"), when this was part of Homebrew Core then installation would be very quick since there all tools are being bottled automatically, which means there's a binary available for download on different OSes. Currently installation of Beak takes a couple of minutes, this would go down to seconds if this was provided via Homebrew Core.

readme errors

In the Shebang section:

  • the two functions need public func before the names
  • ./script.swift run foo should be ./tasks.swift run foo

Document how to run other tools on command line

While Beak is very useful and supports SPM packages, sometimes it would make life much easier if one could run another command line tool to do a specific task instead of writing Swift code for that task. While it is not directly the duty of Beak to teach people how to run command line tools from within Swift, it perfectly makes sense from my point of view to help users by providing one "recommended" way of running them which we will make sure it always works (as long as Swift supports that method).

Especially it can teach Beak users that there's at least the possibility to use other tools from within the Beak script which shows how much more useful Beak can become than they might have initially thought.

Update via Homebrew fails

I have beak 0.3.3 installed on my machine (macOS 10.13.4 & Xcode 9.3) but get an error when trying to upgrade to the latest version (0.3.5). Here's the output:

$ brew upgrade beak
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from 7166289a to 714bf515.
Updated 2 taps (homebrew/core, caskroom/cask).
==> Updated Formulae
annie                       geth                        libphonenumber              pgpool-ii                   sonarqube                   zsh

==> Upgrading 1 outdated package, with result:
yonaskolb/beak/beak 0.3.3 -> 0.3.5
==> Upgrading yonaskolb/beak/beak
==> Downloading https://github.com/yonaskolb/Beak/archive/0.3.5.tar.gz
==> Downloading from https://codeload.github.com/yonaskolb/Beak/tar.gz/0.3.5
######################################################################## 100.0%
==> Building Beak
==> swift build --disable-sandbox -c release -Xswiftc -static-stdlib
Last 15 lines from /Users/Me/Library/Logs/Homebrew/beak/01.swift:
Resolving https://github.com/kylef/Spectre.git at 0.8.0
Cloning https://github.com/drmohundro/SWXMLHash.git
Resolving https://github.com/drmohundro/SWXMLHash.git at 4.6.0
Cloning https://github.com/antitypical/Result.git
Resolving https://github.com/antitypical/Result.git at 3.2.4
Cloning https://github.com/norio-nomura/SourceKit.git
Resolving https://github.com/norio-nomura/SourceKit.git at 1.0.1
Cloning https://github.com/Carthage/Commandant.git
Resolving https://github.com/Carthage/Commandant.git at 0.13.0
Cloning https://github.com/kylef/PathKit.git
Resolving https://github.com/kylef/PathKit.git at 0.9.1
Cloning https://github.com/apple/swift-package-manager
Resolving https://github.com/apple/swift-package-manager at 0.2.0
Cloning https://github.com/norio-nomura/Clang_C.git
Resolving https://github.com/norio-nomura/Clang_C.git at 1.0.2

If reporting this issue please do so to (not Homebrew/brew or Homebrew/core):
yonaskolb/beak

Error: curl failed!
curl: (22) The requested URL returned error: 422 Unprocessable Entity
curl: (3) <url> malformed

Let enum parameters be specified without leading .

When a function has an enum parameter, I need to type the leading dot on the command line for it to work.
e.g: ".none" instead of "none" for an optional parameter

It would be more natural If Beak accepted the parameter without the leading dot.

error: use of unresolved identifier 'exit'

got this at first try, after copying and pasting beak.swift from the example in README.md

$ beak run install

Compile Swift Module 'BeakFile' (1 sources)
**/Users/----/Documents/beak/builds/_Users_icterra/Sources/BeakFile/main.swift:20:5: error: use of unresolved identifier 'exit'
    exit(1)
    ^~~~**

error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/----/Documents/beak/builds/_Users_icterra/.build/debug.yaml main

upgrade to version 0.5.0 failed

Hey,
I recently tried to upgrade Beak to version 0.5.0.

XCode Version: 10.2
Swift Version:

Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0

with following error:

[16:44:10 | NewProjectTemplate-iOS ] brew upgrade beak
==> Upgrading 1 outdated package:
yonaskolb/beak/beak 0.4.0 -> 0.5.0
==> Upgrading yonaskolb/beak/beak
==> Downloading https://github.com/yonaskolb/Beak/archive/0.5.0.tar.gz
Already downloaded: /Users/rocklyve/Library/Caches/Homebrew/downloads/5a0b9ae96158b12b7843a3cd617ee54c57b492fedc00433aaad78083fde4e6ee--Beak-0.5.0.tar.gz
==> Building Beak
==> swift build --disable-sandbox -c release -Xswiftc -static-stdlib
Last 15 lines from /Users/rocklyve/Library/Logs/Homebrew/beak/01.swift:
      _$s8SwiftCLI4TaskC6launch030_19E0ACB72F1C972020BFBD69850F9J1FLLyyF in Task.swift.o
  "_swift_weakLoadStrong", referenced from:
      _$s8SwiftCLI10LineStreamC4eachACySSc_tcfcyycfU_ in Stream.swift.o
      _$s8SwiftCLI13CaptureStreamCACycfcyycfU_ in Stream.swift.o
      _$s8SwiftCLI4TaskC6launch030_19E0ACB72F1C972020BFBD69850F9J1FLLyyFySo6NSTaskCcfU_ in Task.swift.o
  "_swift_willThrow", referenced from:
      _$s7BeakCLI11EditCommandC05SwiftB00D0AadEP7executeyyKFTWTm in BeakCommand.swift.o
      _$s7BeakCLI11EditCommandCAA0aD0A2aDP7execute4path8beakFiley7PathKit0I0V_0A4Core0aH0VtKFTW in EditCommand.swift.o
      _$s7BeakCLI11EditCommandC7execute4path8beakFiley7PathKit0I0V_0A4Core0aH0VtKFTf4nxn_n in EditCommand.swift.o
      _$s7BeakCLI15FunctionCommandCAA0aD0A2aDP7execute4path8beakFiley7PathKit0I0V_0A4Core0aH0VtKFTW in FunctionCommand.swift.o
      _$s7BeakCLI15FunctionCommandC7execute4path8beakFiley7PathKit0I0V_0A4Core0aH0VtKFTf4nxn_n in FunctionCommand.swift.o
      _$s7BeakCLI11ListCommandCAA0aD0A2aDP7execute4path8beakFiley7PathKit0I0V_0A4Core0aH0VtKFTW in ListCommand.swift.o
      _$s7BeakCLI10RunCommandCAA0aD0A2aDP7execute4path8beakFiley7PathKit0I0V_0A4Core0aH0VtKFTW in RunCommand.swift.o
      ...
ld: symbol(s) not found for architecture x86_64

If reporting this issue please do so to (not Homebrew/brew or Homebrew/core):
yonaskolb/beak

Error: Validation Failed: [{"message"=>"The listed users and repositories cannot be searched either because the resources do not exist or you do not have permission to view them.", "resource"=>"Search", "field"=>"q", "code"=>"invalid"}]

Move argument parsing

At the moment Beak parses your function call from the CLI arguments and then embeds that function call at the end of your script and copies it into a main.swift in an executable Swift package.

It would be good to move the argument parsing code into generated package. That way it wouldn't have to be recompiled when you make a different function call (due to the source file changing). And then as it's a self contained package, we can have an install command, that will then copy the built package executable to somewhere like /usr/local/bin

When trying to compile, I get a String error

I'm on Linux, under Swift 4.1

This is what I ran:

felix@felix-X550LD ~/D/P/A/beak> swift build
Compile Swift Module 'BeakCore' (15 sources)
/home/felix/Documents/Programming/AwesomeSystemSwift/beak/Sources/BeakCore/SourceKit.swift:86:54: error: value of type 'String' has no member 'substringWithByteRange'
        let substring = range(for: source).flatMap { contents.substringWithByteRange(start: Int($0.offset), length: Int($0.length)) }
                                                     ^~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
error: terminated(1): /home/felix/Documents/Programming/Binaries/swift/swift-4.1-snapshot/usr/bin/swift-build-tool -f /home/felix/Documents/Programming/AwesomeSystemSwift/beak/.build/debug.yaml main output:
    

This line's the one causing the error. Maybe the library hasn't been updated to Swift 4.1?

Anyway. Thanks for your help, and I hope you have a good day :)

Adding Beak as a package dependency

I'm trying to add Beak as a dependency to my project and import the BeakCore library, but I get this error when building:

Fetching https://github.com/yonaskolb/Beak
error: the package https://github.com/yonaskolb/Beak @ 0.3.3 contains revisioned dependencies:
    https://github.com/yonaskolb/swift-package-manager @ untyped_arguments
error: product dependency 'BeakCore' not found

I believe to fix this issue, https://github.com/yonaskolb/swift-package-manager needs to have a new version tagged on the untyped_arguments branch, and then the Package.swift in this repo needs to be changed from:

...
.package(url: "https://github.com/yonaskolb/swift-package-manager", .branch("untyped_arguments")),
...

to:

...
.package(url: "https://github.com/yonaskolb/swift-package-manager", from: "new-version"),
...

Installation on Docker Ubuntu Failed

Hi, I have successfully installed Beak on MacOS system, but I am having difficulties to do it on Ubuntu 16.04

Platform: Docker image Ubuntu 16.04
Docker image: Swift official image. Swift version 4.1.3

I have created a gist file with the result of my swift run beak run install : Installation

Moreover, I have tried as well using linuxbrew (Homebrew for Debian/Linux) and the tap formulae seems to do not fit the requirements for the installation either.

What am I doing wrong? Some help is appreciated!
I am new using Swift and I think Beak can add a very interesting and simple feature !

Thank you

Edit command removes file attributes

After using beak edit and the final progress of copying the file back, the file attributes are lost. This is a little disturbing if you want to use the Shebang way to run your script, because you always need to execute the chmod again.

break list results misaligned with function docs in file

beak.swift file

/**
 dummy
*/
public func dummy() throws {}

/**
 Releases the product
*/
public func release(version: String) throws {
    // implementation here
    print("version \(version) released! for platform \(platform)")
}

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

/**
 Deletes the product
*/
public func delete() throws {
    // implementation here
    print("deleted")
}
Functions:

  dummy: Releases the product
  release: Installs the product
  install: Deletes the product
  delete: 

would have expected:

Functions:

  dummy: dummy
  release: Releases the product
  install: Installs the product
  delete: Deletes the product

same results regardless of using /** */ or ///

Script execution rules

At the moment how Beak runs the swift script is by embedding your function call at the end of the script and then copying it into a main.swift in an executable Swift package.
This means any free code in the script will also be run

public func foo() {
  print("Foo called")
}
print("This still runs")
$ beak run foo
  This still runs
  Foo called

This is useful as it's an easy place to put code that should run before every function call. It also means we could potentially allow beak run without specifying a function. That means it will just run the script, giving it functionality similar to Marathon https://github.com/JohnSundell/Marathon.

The other option is to leave the script untouched and generate a new main.swift file that just includes the function call, while also linking the original script as a seperate file. This would in affect only run the passed function, as top level expressions aren't allowed in non main files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.