mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-30 09:51:03 +02:00
Merge pull request #18 from sbarzowski/cmd
Basic commandline (so we can start testing compatibility)
This commit is contained in:
commit
dee39c1163
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
*~
|
*~
|
||||||
.*.swp
|
.*.swp
|
||||||
|
/tests_path.source
|
||||||
|
50
jsonnet/cmd.go
Normal file
50
jsonnet/cmd.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Google Inc. All rights reserved.
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/google/go-jsonnet"
|
||||||
|
)
|
||||||
|
|
||||||
|
func usage() {
|
||||||
|
fmt.Println("usage: jsonnet <filename>")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// TODO(sbarzowski) Be consistent about error codes with C++ maybe
|
||||||
|
vm := jsonnet.MakeVM()
|
||||||
|
if len(os.Args) != 2 {
|
||||||
|
usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
filename := os.Args[1]
|
||||||
|
snippet, err := ioutil.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error reading input file: %v\n", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
json, err := vm.EvaluateSnippet(filename, string(snippet))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "%v\n", err.Error())
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
fmt.Println(json)
|
||||||
|
}
|
BIN
jsonnet/jsonnet
Executable file
BIN
jsonnet/jsonnet
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user