Skip to content

Commit

Permalink
Add scripts/genny.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
  • Loading branch information
Vladimir Popov committed Dec 4, 2020
1 parent c1dc3b6 commit ddf7cd1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/tools/metadatahelper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gen.go:
```go
package connect

//go:generate genny -in=../../../tools/metadatahelper/meta_data.template.go -out=client_meta_data.gen.go -pkg=connect gen "prefix=client valueType=networkservice.NetworkServiceClient"
//go:generate bash ../../../../scripts/genny.sh -in=github.com/networkservicemesh/sdk/pkg/tools/metadatahelper/meta_data.template.go -out=client_meta_data.gen.go gen "prefix=client valueType=networkservice.NetworkServiceClient"
```
client_meta_data.gen.go:
```go
Expand Down
2 changes: 1 addition & 1 deletion pkg/tools/metadatahelper/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package metadatahelper

//go:generate genny -in=meta_data.template.go -out=int_meta_data.gen.go gen "prefix=Int valueType=int"
//go:generate bash ../../../scripts/genny.sh -in=github.com/networkservicemesh/sdk/pkg/tools/metadatahelper/meta_data.template.go -out=int_meta_data.gen.go gen "prefix=Int valueType=int"
65 changes: 65 additions & 0 deletions scripts/genny.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

# Copyright (c) 2020 Doc.ai and/or its affiliates.
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

PRG_NAME="$0"

function usage() {
echo "${PRG_NAME} -in=package/file.template.go -out=file.gen.go gen \"KeyType=string,int ValueType=string,int\""
}

######################
# Parse args
######################

template=
out=
gen=

while [[ $# -ne 0 ]]; do
if [[ "$1" == -in=* ]]; then
template="${1#"-in="}"
shift
elif [[ "$1" == -out=* ]]; then
out="${1#"-out="}"
shift
elif [[ "$1" == "gen" ]]; then
gen="$2"
shift 2
if [[ $# -ne 0 ]]; then
usage && exit 1
fi
else
usage && exit 1
fi
done

######################
# Find template file
######################

package="$(echo "${template}" | sed -E "s/(.*)\/.*/\1/g")"
root="$(go list -f "{{.Root}}" "${package}")"

module="$(go list -f "{{.Module}}" "${package}" | sed -E "s/([.]*) .*/\1/g")"
path="${template#${module}}"

######################
# Call genny
######################

genny "-in=${root}/${path}" "-out=${out}" "-pkg=${GOPACKAGE}" gen "${gen}"

0 comments on commit ddf7cd1

Please sign in to comment.