From 834a8353f47dba0324657a1799dc0d462d06c029 Mon Sep 17 00:00:00 2001
From: Prashant Varanasi
Date: Wed, 6 Sep 2017 15:17:32 -0700
Subject: [PATCH 1/4] Support yab as a shebang without -y (#215)
Shebangs cannot contain flags on Linux, so our recommendation to use
```
```
doesn't work on Linux.
Instead, have yab look at the first argument, and if it's a valid file
ending in .yab, then don't require -y. This is a little bit of "magic"
but will make the user experience better (so users don't have to
remember to use a separate script called yaby or something).
Fixes #198.
---
CHANGELOG.md | 3 +++
doc.go | 4 +--
main.go | 17 +++++++++++++
main_test.go | 32 +++++++++++++++++++++++-
template_test.go | 4 +--
testdata/templates/{foo.yaml => foo.yab} | 0
utils_for_test.go | 2 +-
7 files changed, 56 insertions(+), 6 deletions(-)
rename testdata/templates/{foo.yaml => foo.yab} (100%)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 57de9ac8..f92810c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,9 @@
Changelog
=========
+# 0.11.0 (Unreleased)
+* Support using yab as a shebang for files ending with `.yab`.
+
# 0.10.2 (2017-08-29)
* Fix timeouts specified in templates being ignored.
diff --git a/doc.go b/doc.go
index 34df4d53..11b85508 100644
--- a/doc.go
+++ b/doc.go
@@ -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
@@ -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
diff --git a/main.go b/main.go
index a5b67f3d..ffdb2c29 100644
--- a/main.go
+++ b/main.go
@@ -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
}
@@ -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
+}
diff --git a/main_test.go b/main_test.go
index d0fe76ae..e194b259 100644
--- a/main_test.go
+++ b/main_test.go
@@ -914,7 +914,7 @@ func TestTemplates(t *testing.T) {
echoAddr := echoServer(t, "", []byte{0})
os.Args = []string{
"yab",
- "-y", exampleTemplate,
+ exampleTemplate,
"-p", echoAddr,
}
@@ -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))
+ })
+ }
+}
diff --git a/template_test.go b/template_test.go
index b8c6c027..cffe7c31 100644
--- a/template_test.go
+++ b/template_test.go
@@ -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)
@@ -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")
diff --git a/testdata/templates/foo.yaml b/testdata/templates/foo.yab
similarity index 100%
rename from testdata/templates/foo.yaml
rename to testdata/templates/foo.yab
diff --git a/utils_for_test.go b/utils_for_test.go
index 0fe0ffd7..673f8efa 100644
--- a/utils_for_test.go
+++ b/utils_for_test.go
@@ -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()
From 944a66a0315b72eca2d44fa5c7e3be8b1a3908b2 Mon Sep 17 00:00:00 2001
From: Prashant Varanasi
Date: Wed, 6 Sep 2017 15:21:09 -0700
Subject: [PATCH 2/4] Regenerate man page and README for latest flags (#216)
---
README.md | 2 ++
man/yab.1 | 11 +++++++----
man/yab.html | 32 +++++++++++++++++++++++++-------
3 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index e580a5c3..0e12d9b1 100644
--- a/README.md
+++ b/README.md
@@ -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:
diff --git a/man/yab.1 b/man/yab.1
index 49509bd2..3aaa9e38 100644
--- a/man/yab.1
+++ b/man/yab.1
@@ -1,4 +1,4 @@
-.TH yab 1 "7 April 2017"
+.TH yab 1 "6 September 2017"
.SH NAME
yab \- yet another benchmarker
.SH SYNOPSIS
@@ -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
@@ -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
@@ -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
@@ -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 \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
diff --git a/man/yab.html b/man/yab.html
index 39f32c4b..e5491d4c 100644
--- a/man/yab.html
+++ b/man/yab.html
@@ -1,5 +1,5 @@
-
+
@@ -77,8 +77,26 @@ OPTIONS
Application
-Options
-−−version
+Options
+
+
+
+ |
+
+
+
+ −v |
+ |
+
+
+
+ Enable more detailed logging. Repeats
+increase the verbosity, ie. -vvv |
+
+
+
+−−version
Displays the application
version
@@ -158,7 +176,7 @@ OPTIONS
you add a shebang and mark the file as executable:
#!/usr/bin/env
-yab -y
+yab
service: kv
@@ -176,7 +194,7 @@
OPTIONS
YAML template to take an argument for the key:
#!/usr/bin/env
-yab -y
+yab
service: kv
@@ -323,8 +341,8 @@
OPTIONS
Hit the health endpoint,
Meta::health
-−−timeout
-<default: "1s">
+
+−−timeout
The timeout for each request.
E.g., 100ms, 0.5s, 1s. If no unit is specified, milliseconds
From 7dd636850c669cfd2d8ccc0566de4aa718471395 Mon Sep 17 00:00:00 2001
From: Prashant Varanasi
Date: Wed, 6 Sep 2017 15:22:54 -0700
Subject: [PATCH 3/4] Prepare for v0.11.0 release (#217)
---
CHANGELOG.md | 2 +-
version.go | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f92810c3..30a2c9c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,7 @@
Changelog
=========
-# 0.11.0 (Unreleased)
+# 0.11.0 (2017-09-06)
* Support using yab as a shebang for files ending with `.yab`.
# 0.10.2 (2017-08-29)
diff --git a/version.go b/version.go
index ef870ad2..53ac62b8 100644
--- a/version.go
+++ b/version.go
@@ -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"
From 5142eecab80bda5bf42869442d058429bce6d218 Mon Sep 17 00:00:00 2001
From: Prashant Varanasi
Date: Wed, 6 Sep 2017 15:39:46 -0700
Subject: [PATCH 4/4] Fix release script to handle dates in changelogs (#218)
---
scripts/extract_changelog.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/extract_changelog.go b/scripts/extract_changelog.go
index 0d742045..a7dc8871 100644
--- a/scripts/extract_changelog.go
+++ b/scripts/extract_changelog.go
@@ -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: