diff --git a/CHANGELOG.md b/CHANGELOG.md
index 57de9ac8..30a2c9c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
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/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/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 Application
-Options OPTIONS
-−−version
+ |
+
+
+ −v |
++ |
+
+
+ Enable more detailed logging. Repeats +increase the verbosity, ie. -vvv |
+
−−version
Displays the application version
@@ -158,7 +176,7 @@#!/usr/bin/env -yab -y
+yabservice: kv
@@ -176,7 +194,7 @@
#!/usr/bin/env -yab -y
+yabservice: kv
@@ -323,8 +341,8 @@
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 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: 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() 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"