Skip to content

Commit

Permalink
Merge pull request #219 from yarpc/dev
Browse files Browse the repository at this point in the history
Release v0.11.0
  • Loading branch information
prashantv authored Sep 7, 2017
2 parents f20afb9 + 5142eec commit fd2c626
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
=========

# 0.11.0 (2017-09-06)
* Support using yab as a shebang for files ending with `.yab`.

# 0.10.2 (2017-08-29)
* Fix timeouts specified in templates being ignored.

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ http://yarpc.github.io/yab/man.html
Application Options:
-v Enable more detailed logging. Repeats increase
the verbosity, ie. -vvv
--version Displays the application version
Request Options:
Expand Down
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ be run using yab -y get.yab.
You can make the request by directly executing the file (./get.yab) if you
add a shebang and mark the file as executable:
#!/usr/bin/env yab -y
#!/usr/bin/env yab
service: kv
peer: localhost:9787
Expand All @@ -92,7 +92,7 @@ which can be specified on the command line using -A. If an argument is not
specified on the command line, then the default value is used. For example,
we can update the YAML template to take an argument for the key:
#!/usr/bin/env yab -y
#!/usr/bin/env yab
service: kv
peer: localhost:9787
Expand Down
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ yab includes a full man page (man yab), which is also available online: http://y
return nil, fmt.Errorf("error reading defaults: %v", err)
}

// Check if the first argument is a yab template. This is to support using
// yab as a shebang, since flags aren't supported in shebangs.
if len(args) > 0 && isYabTemplate(args[0]) {
args = append([]string{"-y"}, args...)
}

if err := overrideDefaults(opts, args); err != nil {
return nil, err
}
Expand Down Expand Up @@ -421,3 +427,14 @@ func makeInitialRequest(out output, transport transport.Transport, serializer en
}
out.Printf("%s\n\n", bs)
}

// isYabTemplate is currently very conservative, it requires a file that exists
// that ends with .yab to detect the argument as a template.
func isYabTemplate(s string) bool {
if !strings.HasSuffix(s, ".yab") {
return false
}

_, err := os.Stat(s)
return err == nil
}
32 changes: 31 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ func TestTemplates(t *testing.T) {
echoAddr := echoServer(t, "", []byte{0})
os.Args = []string{
"yab",
"-y", exampleTemplate,
exampleTemplate,
"-p", echoAddr,
}

Expand Down Expand Up @@ -1113,3 +1113,33 @@ func TestOptionsInheritance(t *testing.T) {
}
}
}

func TestIsYabTemplate(t *testing.T) {
tests := []struct {
msg string
f string
want bool
}{
{
msg: "exists without .yab suffix",
f: "testdata/templates/args.yaml",
want: false,
},
{
msg: "exists with .yab suffix",
f: "testdata/templates/foo.yab",
want: true,
},
{
msg: "doesn't exist with .yab suffix",
f: "testdata/not-exist.yab",
want: false,
},
}

for _, tt := range tests {
t.Run(tt.msg, func(t *testing.T) {
assert.Equal(t, tt.want, isYabTemplate(tt.f))
})
}
}
11 changes: 7 additions & 4 deletions man/yab.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH yab 1 "7 April 2017"
.TH yab 1 "6 September 2017"
.SH NAME
yab \- yet another benchmarker
.SH SYNOPSIS
Expand Down Expand Up @@ -47,6 +47,9 @@ warmup = 10
.SH OPTIONS
.SS Application Options
.TP
\fB\fB\-v\fR\fP
Enable more detailed logging. Repeats increase the verbosity, ie. -vvv
.TP
\fB\fB\-\-version\fR\fP
Displays the application version
.SS Request Options
Expand Down Expand Up @@ -158,7 +161,7 @@ add a shebang and mark the file as executable:
.PP
.nf
.RS
#!/usr/bin/env yab -y
#!/usr/bin/env yab
.RE
.fi
.PP
Expand Down Expand Up @@ -200,7 +203,7 @@ we can update the YAML template to take an argument for the key:
.PP
.nf
.RS
#!/usr/bin/env yab -y
#!/usr/bin/env yab
.RE
.fi
.PP
Expand Down Expand Up @@ -319,7 +322,7 @@ Individual context baggage header as a key:value pair per flag
\fB\fB\-\-health\fR\fP
Hit the health endpoint, Meta::health
.TP
\fB\fB\-\-timeout\fR <default: \fI"1s"\fR>\fP
\fB\fB\-\-timeout\fR\fP
The timeout for each request. E.g., 100ms, 0.5s, 1s. If no unit is specified, milliseconds are assumed.
.TP
\fB\fB\-y\fR, \fB\-\-yaml-template\fR\fP
Expand Down
32 changes: 25 additions & 7 deletions man/yab.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/extract_changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func run(version string, out io.Writer) error {

switch state {
case searching:
if line == "# "+version {
if strings.HasPrefix(line, "# "+version+" (") {
state = foundHeader
}
case foundHeader:
Expand Down
4 changes: 2 additions & 2 deletions template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func getWd(t *testing.T) string {

func TestTemplate(t *testing.T) {
opts := newOptions()
mustReadYAMLFile(t, "testdata/templates/foo.yaml", opts)
mustReadYAMLFile(t, "testdata/templates/foo.yab", opts)

assert.Equal(t, toAbsPath(t, "testdata/templates/foo.thrift"), opts.ROpts.ThriftFile)
assert.Equal(t, "Simple::foo", opts.ROpts.Procedure)
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestTemplateHeadersMerge(t *testing.T) {
"header3": "from Headers",
}

mustReadYAMLFile(t, "testdata/templates/foo.yaml", opts)
mustReadYAMLFile(t, "testdata/templates/foo.yab", opts)

headers, err := getHeaders(opts.ROpts.HeadersJSON, opts.ROpts.HeadersFile, opts.ROpts.Headers)
assert.NoError(t, err, "failed to merge headers")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion utils_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
const (
validThrift = "testdata/simple.thrift"
fooMethod = "Simple::foo"
exampleTemplate = "testdata/templates/foo.yaml"
exampleTemplate = "testdata/templates/foo.yab"
)

var _testLogger = zap.NewNop()
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ package main

// versionString is the sem-ver version string for yab.
// It will be bumped explicitly on releases.
var versionString = "0.10.2"
var versionString = "0.11.0"

0 comments on commit fd2c626

Please sign in to comment.