Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
speier committed Nov 26, 2021
1 parent 58753a8 commit 05c167d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
21 changes: 13 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
build:
binary: hrun
goos:
- linux
- darwin
- windows
goarch:
- amd64
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ POST(`${host}/post`, 'Accept: application/vnd.foobar.v2+json', { payload: { data
Run the script:

```sh
$ hrun -f examples/basic.js
$ hrun examples/basic.js
```

## API
Expand Down
28 changes: 26 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,54 @@
package main

import (
"errors"
"flag"
"fmt"
"os"

"github.com/speier/hrun/pkg/req"
"github.com/speier/hrun/pkg/utils"
"github.com/speier/hrun/pkg/vm"
)

const (
usage = `Usage: hrun [OPTIONS] <filename>
Options:
`
)

var (
envargs utils.ArrayFlag
)

func init() {
flag.Var(&envargs, "e", "env var or file (repeatable)")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), usage)
flag.PrintDefaults()
}
flag.Parse()
}

func main() {
// just append a new line to make output more readable
fmt.Println()

// check if file exists
filename := flag.Arg(0)
if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
flag.Usage()
os.Exit(0)
}

// init vm
vm := vm.NewInterpreter(req.Methods)
vm.Set("env", utils.VMEnv(envargs))

// run script
_, err := vm.RunFile(flag.Arg(0))
_, err := vm.RunFile(filename)
if err != nil {
println(err.Error())
fmt.Println(err.Error())
}
}
4 changes: 2 additions & 2 deletions pkg/req/res.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type Response struct {

func (r *Response) String() string {
sb := &strings.Builder{}
fmt.Fprintf(sb, "\n[%d] %s\n", r.StatusCode, r.Host)
fmt.Fprintf(sb, "%s\n", r.Body)
fmt.Fprintf(sb, "[%d] %s\n", r.StatusCode, r.Host)
fmt.Fprintf(sb, "%s", r.Body)
return sb.String()
}

Expand Down

0 comments on commit 05c167d

Please sign in to comment.