Skip to content

Commit

Permalink
Lowercase the webrpc-cli custom -options
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVitek committed Nov 8, 2022
1 parent f43dabc commit 291f8ef
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@ write by hand.
## Usage

```
webrpc-gen -schema=example.ridl -target=javascript -Server -Client -out=./example.gen.ts
webrpc-gen -schema=example.ridl -target=javascript -server -client -out=./example.gen.ts
```

or

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

or

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

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

| CLI option flag | Description | Default value |
|----------------------|----------------------------|----------------------------|
| `-Client` | generate client code | unset (`false`) |
| `-Server` | generate server code | unset (`false`) |
| `-Exports=false` | disable "exports" in code | enabled (`true`) |
| `-client` | generate client code | unset (`false`) |
| `-server` | generate server code | unset (`false`) |
| `-exports=false` | disable "exports" in code | enabled (`true`) |

Example:
```
webrpc-gen -schema=example.ridl -target=javascript -Server -Client -Exports=false -out=./example.gen.js
webrpc-gen -schema=example.ridl -target=javascript -server -client -exports=false -out=./example.gen.js
```

## LICENSE
Expand Down
2 changes: 1 addition & 1 deletion _examples/hello-webrpc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ generate-server:
webrpc-gen -schema=hello-api.ridl -target=go -pkg=main -server -out=./server/hello_api.gen.go

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

run-server:
go run ./server
Expand Down
2 changes: 1 addition & 1 deletion _examples/hello-webrpc/webapp/client.gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// --
// Code generated by [email protected] with custom generator. DO NOT EDIT.
//
// webrpc-gen -schema=hello-api.ridl -target=../../ -Export=false -client -out=./webapp/client.gen.js
// webrpc-gen -schema=hello-api.ridl -target=../../ -exports=false -client -out=./webapp/client.gen.js

// WebRPC description and code-gen version
export const WebRPCVersion = "v1"
Expand Down
2 changes: 1 addition & 1 deletion client.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Client
//
{{ range .Services}}
{{if $opts.Export}}export {{end}}class {{.Name}} {
{{if $opts.exports}}export {{end}}class {{.Name}} {
constructor(hostname, fetch) {
this.path = '/rpc/{{.Name}}/'
this.hostname = hostname
Expand Down
2 changes: 1 addition & 1 deletion help.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- define "help" -}}
{{- stderrPrintf "\nAvailable template options:\n" -}}
{{- range $k, $v := . -}}
{{- stderrPrintf " -%v=%v\n" $k $v -}}
{{- end -}}
{{- stderrPrintf "See https://github.com/webrpc/gen-javascript for more info.\n" -}}
{{- end -}}
38 changes: 19 additions & 19 deletions main.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
{{- define "main" -}}

{{- if ne .WebrpcVersion "v1" -}}
{{- stderrPrintf "%s generator error: unsupported webrpc version %s\n" .WebrpcTarget .WebrpcVersion -}}
{{- exit 1 -}}
{{- end -}}

{{- if not (minVersion .WebrpcGenVersion "v0.7.0") -}}
{{- stderrPrintf "%s generator error: unsupported webrpc-gen version %s, please update\n" .WebrpcTarget .WebrpcGenVersion -}}
{{- exit 1 -}}
{{- end -}}

{{- /* Options with default values. */ -}}
{{- $opts := dict -}}
{{- set $opts "Client" (ternary (in .Opts.Client "" "true") true false) -}}
{{- set $opts "Server" (ternary (in .Opts.Server "" "true") true false) -}}
{{- set $opts "Export" (ternary (in .Opts.Export "false") false true) -}}
{{- set $opts "client" (ternary (in .Opts.client "" "true") true false) -}}
{{- set $opts "server" (ternary (in .Opts.server "" "true") true false) -}}
{{- set $opts "exports" (ternary (in .Opts.exports "false") false true) -}}

{{- /* Print help on -Help. */ -}}
{{- if exists .Opts "Help" -}}
{{ template "help" $opts }}
{{- /* Print help on -help. */ -}}
{{- if exists .Opts "help" -}}
{{- template "help" $opts -}}
{{- exit 0 -}}
{{- end -}}

{{- /* Print help on unsupported option. */ -}}
{{- range $k, $v := .Opts }}
{{- if not (exists $opts $k) -}}
{{- stderrPrintf " -%v=%q is not supported option\n" $k $v -}}
{{- stderrPrintf "-%v=%q is not supported target option\n\nUsage:\n" $k $v -}}
{{- template "help" $opts -}}
{{- exit 1 -}}
{{- end -}}
{{- end -}}

{{- if ne .WebrpcVersion "v1" -}}
{{- stderrPrintf "%s generator error: unsupported webrpc version %s\n" .WebrpcTarget .WebrpcVersion -}}
{{- exit 1 -}}
{{- end -}}

{{- if not (minVersion .WebrpcGenVersion "v0.7.0") -}}
{{- stderrPrintf "%s generator error: unsupported webrpc-gen version %s, please update\n" .WebrpcTarget .WebrpcGenVersion -}}
{{- exit 1 -}}
{{- end -}}

{{- /* Map webrpc data types to JS. */ -}}
{{- $typeMap := dict }}
{{- set $typeMap "null" "null" -}}
Expand Down Expand Up @@ -68,11 +68,11 @@ export const WebRPCSchemaVersion = "{{.SchemaVersion}}"
export const WebRPCSchemaHash = "{{.SchemaHash}}"

{{template "types" dict "Services" .Services "Messages" .Messages "Opts" $opts}}
{{- if $opts.Client}}
{{- if $opts.client}}
{{template "client" dict "Services" .Services "Opts" $opts}}
{{template "client_helpers" .}}
{{- end}}
{{- if $opts.Server}}
{{- if $opts.server}}
{{template "server" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap}}
{{- end}}
{{- end}}
4 changes: 2 additions & 2 deletions types.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{{if .Type | isEnumType -}}
{{$enumName := .Name}}
{{if $opts.Export}}export {{end}}var {{$enumName}};
{{if $opts.exports}}export {{end}}var {{$enumName}};
(function ({{$enumName}}) {
{{- range $i, $field := .Fields}}
{{$enumName}}["{{$field.Name}}"] = "{{$field.Name}}"
Expand All @@ -19,7 +19,7 @@
{{end -}}

{{- if .Type | isStructType }}
{{if $opts.Export}}export {{end}}class {{.Name}} {
{{if $opts.exports}}export {{end}}class {{.Name}} {
constructor(_data) {
this._data = {}
if (_data) {
Expand Down

0 comments on commit 291f8ef

Please sign in to comment.