2019-01-24 03:30:41 +03:00
|
|
|
|
# Tengo CLI Tool
|
|
|
|
|
|
2019-12-20 22:40:38 +03:00
|
|
|
|
Tengo is designed as an embedding script language for Go, but, it can also be
|
|
|
|
|
compiled and executed as native binary using `tengo` CLI tool.
|
2019-01-24 03:30:41 +03:00
|
|
|
|
|
|
|
|
|
## Installing Tengo CLI
|
|
|
|
|
|
|
|
|
|
To install `tengo` tool, run:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
go get github.com/d5/tengo/cmd/tengo
|
|
|
|
|
```
|
|
|
|
|
|
2019-12-20 22:40:38 +03:00
|
|
|
|
Or, you can download the precompiled binaries from
|
2020-03-04 17:53:38 +03:00
|
|
|
|
[here](https://github.com/d5/tengo/releases/latest).
|
2019-01-30 12:05:35 +03:00
|
|
|
|
|
2019-01-24 03:30:41 +03:00
|
|
|
|
## Compiling and Executing Tengo Code
|
|
|
|
|
|
2019-12-20 22:40:38 +03:00
|
|
|
|
You can directly execute the Tengo source code by running `tengo` tool with
|
|
|
|
|
your Tengo source file (`*.tengo`).
|
2019-01-24 03:30:41 +03:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
tengo myapp.tengo
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Or, you can compile the code into a binary file and execute it later.
|
|
|
|
|
|
|
|
|
|
```bash
|
2019-01-30 12:23:26 +03:00
|
|
|
|
tengo -o myapp myapp.tengo # compile 'myapp.tengo' into binary file 'myapp'
|
2020-03-04 17:53:38 +03:00
|
|
|
|
tengo myapp # execute the compiled binary `myapp`
|
2019-01-24 03:30:41 +03:00
|
|
|
|
```
|
|
|
|
|
|
2020-05-08 20:09:44 +03:00
|
|
|
|
Or, you can make tengo source file executable
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# copy tengo executable to a dir where PATH environment variable includes
|
|
|
|
|
cp tengo /usr/local/bin/
|
|
|
|
|
|
|
|
|
|
# add shebang line to source file
|
|
|
|
|
cat > myapp.tengo << EOF
|
|
|
|
|
#!/usr/local/bin/tengo
|
|
|
|
|
fmt := import("fmt")
|
|
|
|
|
fmt.println("Hello World!")
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
# make myapp.tengo file executable
|
|
|
|
|
chmod +x myapp.tengo
|
|
|
|
|
|
|
|
|
|
# run your script
|
|
|
|
|
./myapp.tengo
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Note: Your source file must have `.tengo` extension.**
|
|
|
|
|
|
2020-06-08 19:54:24 +03:00
|
|
|
|
## Resolving Relative Import Paths
|
|
|
|
|
|
|
|
|
|
If there are tengo source module files which are imported with relative import
|
|
|
|
|
paths, CLI has `-resolve` flag. Flag enables to import a module relative to
|
|
|
|
|
importing file. This behavior will be default at version 3.
|
|
|
|
|
|
2019-01-24 03:30:41 +03:00
|
|
|
|
## Tengo REPL
|
|
|
|
|
|
2019-12-20 22:40:38 +03:00
|
|
|
|
You can run Tengo [REPL](https://en.wikipedia.org/wiki/Read–eval–print_loop)
|
|
|
|
|
if you run `tengo` with no arguments.
|
2019-01-24 03:30:41 +03:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
tengo
|
2020-03-04 17:53:38 +03:00
|
|
|
|
```
|