Skip to content

Commit 291f8ef

Browse files
committed
Lowercase the webrpc-cli custom -options
1 parent f43dabc commit 291f8ef

File tree

7 files changed

+32
-32
lines changed

7 files changed

+32
-32
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,33 @@ write by hand.
2020
## Usage
2121

2222
```
23-
webrpc-gen -schema=example.ridl -target=javascript -Server -Client -out=./example.gen.ts
23+
webrpc-gen -schema=example.ridl -target=javascript -server -client -out=./example.gen.ts
2424
```
2525

2626
or
2727

2828
```
29-
webrpc-gen -schema=example.ridl -target=github.com/webrpc/[email protected] -Server -Client -out=./example.gen.js
29+
webrpc-gen -schema=example.ridl -target=github.com/webrpc/[email protected] -server -client -out=./example.gen.js
3030
```
3131

3232
or
3333

3434
```
35-
webrpc-gen -schema=example.ridl -target=./local-templates-on-disk -Server -Client -out=./example.gen.js
35+
webrpc-gen -schema=example.ridl -target=./local-templates-on-disk -server -client -out=./example.gen.js
3636
```
3737

3838
### Set custom template variables
3939
Change any of the following values by passing `-Option="Value"` CLI flag to `webrpc-gen`.
4040

4141
| CLI option flag | Description | Default value |
4242
|----------------------|----------------------------|----------------------------|
43-
| `-Client` | generate client code | unset (`false`) |
44-
| `-Server` | generate server code | unset (`false`) |
45-
| `-Exports=false` | disable "exports" in code | enabled (`true`) |
43+
| `-client` | generate client code | unset (`false`) |
44+
| `-server` | generate server code | unset (`false`) |
45+
| `-exports=false` | disable "exports" in code | enabled (`true`) |
4646

4747
Example:
4848
```
49-
webrpc-gen -schema=example.ridl -target=javascript -Server -Client -Exports=false -out=./example.gen.js
49+
webrpc-gen -schema=example.ridl -target=javascript -server -client -exports=false -out=./example.gen.js
5050
```
5151

5252
## LICENSE

_examples/hello-webrpc/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ generate-server:
1010
webrpc-gen -schema=hello-api.ridl -target=go -pkg=main -server -out=./server/hello_api.gen.go
1111

1212
generate-client:
13-
webrpc-gen -schema=hello-api.ridl -target=../../ -Export=false -client -out=./webapp/client.gen.js
13+
webrpc-gen -schema=hello-api.ridl -target=../../ -exports=false -client -out=./webapp/client.gen.js
1414

1515
run-server:
1616
go run ./server

_examples/hello-webrpc/webapp/client.gen.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// --
33
// Code generated by [email protected] with custom generator. DO NOT EDIT.
44
//
5-
// webrpc-gen -schema=hello-api.ridl -target=../../ -Export=false -client -out=./webapp/client.gen.js
5+
// webrpc-gen -schema=hello-api.ridl -target=../../ -exports=false -client -out=./webapp/client.gen.js
66

77
// WebRPC description and code-gen version
88
export const WebRPCVersion = "v1"

client.go.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Client
88
//
99
{{ range .Services}}
10-
{{if $opts.Export}}export {{end}}class {{.Name}} {
10+
{{if $opts.exports}}export {{end}}class {{.Name}} {
1111
constructor(hostname, fetch) {
1212
this.path = '/rpc/{{.Name}}/'
1313
this.hostname = hostname

help.go.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- define "help" -}}
2-
{{- stderrPrintf "\nAvailable template options:\n" -}}
32
{{- range $k, $v := . -}}
43
{{- stderrPrintf " -%v=%v\n" $k $v -}}
54
{{- end -}}
5+
{{- stderrPrintf "See https://github.com/webrpc/gen-javascript for more info.\n" -}}
66
{{- end -}}

main.go.tmpl

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
{{- define "main" -}}
22

3-
{{- if ne .WebrpcVersion "v1" -}}
4-
{{- stderrPrintf "%s generator error: unsupported webrpc version %s\n" .WebrpcTarget .WebrpcVersion -}}
5-
{{- exit 1 -}}
6-
{{- end -}}
7-
8-
{{- if not (minVersion .WebrpcGenVersion "v0.7.0") -}}
9-
{{- stderrPrintf "%s generator error: unsupported webrpc-gen version %s, please update\n" .WebrpcTarget .WebrpcGenVersion -}}
10-
{{- exit 1 -}}
11-
{{- end -}}
12-
133
{{- /* Options with default values. */ -}}
144
{{- $opts := dict -}}
15-
{{- set $opts "Client" (ternary (in .Opts.Client "" "true") true false) -}}
16-
{{- set $opts "Server" (ternary (in .Opts.Server "" "true") true false) -}}
17-
{{- set $opts "Export" (ternary (in .Opts.Export "false") false true) -}}
5+
{{- set $opts "client" (ternary (in .Opts.client "" "true") true false) -}}
6+
{{- set $opts "server" (ternary (in .Opts.server "" "true") true false) -}}
7+
{{- set $opts "exports" (ternary (in .Opts.exports "false") false true) -}}
188

19-
{{- /* Print help on -Help. */ -}}
20-
{{- if exists .Opts "Help" -}}
21-
{{ template "help" $opts }}
9+
{{- /* Print help on -help. */ -}}
10+
{{- if exists .Opts "help" -}}
11+
{{- template "help" $opts -}}
2212
{{- exit 0 -}}
2313
{{- end -}}
2414

2515
{{- /* Print help on unsupported option. */ -}}
2616
{{- range $k, $v := .Opts }}
2717
{{- if not (exists $opts $k) -}}
28-
{{- stderrPrintf " -%v=%q is not supported option\n" $k $v -}}
18+
{{- stderrPrintf "-%v=%q is not supported target option\n\nUsage:\n" $k $v -}}
2919
{{- template "help" $opts -}}
3020
{{- exit 1 -}}
3121
{{- end -}}
3222
{{- end -}}
3323

24+
{{- if ne .WebrpcVersion "v1" -}}
25+
{{- stderrPrintf "%s generator error: unsupported webrpc version %s\n" .WebrpcTarget .WebrpcVersion -}}
26+
{{- exit 1 -}}
27+
{{- end -}}
28+
29+
{{- if not (minVersion .WebrpcGenVersion "v0.7.0") -}}
30+
{{- stderrPrintf "%s generator error: unsupported webrpc-gen version %s, please update\n" .WebrpcTarget .WebrpcGenVersion -}}
31+
{{- exit 1 -}}
32+
{{- end -}}
33+
3434
{{- /* Map webrpc data types to JS. */ -}}
3535
{{- $typeMap := dict }}
3636
{{- set $typeMap "null" "null" -}}
@@ -68,11 +68,11 @@ export const WebRPCSchemaVersion = "{{.SchemaVersion}}"
6868
export const WebRPCSchemaHash = "{{.SchemaHash}}"
6969

7070
{{template "types" dict "Services" .Services "Messages" .Messages "Opts" $opts}}
71-
{{- if $opts.Client}}
71+
{{- if $opts.client}}
7272
{{template "client" dict "Services" .Services "Opts" $opts}}
7373
{{template "client_helpers" .}}
7474
{{- end}}
75-
{{- if $opts.Server}}
75+
{{- if $opts.server}}
7676
{{template "server" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap}}
7777
{{- end}}
7878
{{- end}}

types.go.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
{{if .Type | isEnumType -}}
1212
{{$enumName := .Name}}
13-
{{if $opts.Export}}export {{end}}var {{$enumName}};
13+
{{if $opts.exports}}export {{end}}var {{$enumName}};
1414
(function ({{$enumName}}) {
1515
{{- range $i, $field := .Fields}}
1616
{{$enumName}}["{{$field.Name}}"] = "{{$field.Name}}"
@@ -19,7 +19,7 @@
1919
{{end -}}
2020

2121
{{- if .Type | isStructType }}
22-
{{if $opts.Export}}export {{end}}class {{.Name}} {
22+
{{if $opts.exports}}export {{end}}class {{.Name}} {
2323
constructor(_data) {
2424
this._data = {}
2525
if (_data) {

0 commit comments

Comments
 (0)