Skip to content

Commit

Permalink
Add documentation for VARIANT_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Sep 26, 2020
1 parent 1cbc008 commit eed652c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ Head over to the following per-topic sections for more features:
- [Debugging Commands](#debugging-commands) to learn how to debug your Variant command
- [Writing Tests](#writing-tests) to learn the Variant DSL for writing tests
- [Generating Shims](#generating-shims) to make your Variant command look native
- [Compiling Command](#compiling-command) to export Go source or an executable binary
- [Running Command From Other Directory](#running-command-from-another-directory)
- [Concurrency](#concurrency) section to make `kubectl` and `helm` concurrent so that the installation time becomes minimal
- [Log Collection](#log-collection) to filter and forward log of commands and the arguments passed to them along with their outputs
- Use [Split, Merge and Import](#split-merge-and-import) to split, compose and tidy Variant commands
Expand Down Expand Up @@ -189,6 +191,52 @@ Flags:
Use "getting-started [command] --help" for more information about a command.
```

## Compiling Command

As we've covered in the [Getting Started](#getting-started) guide, `variant export` sub-commands can be used to export
your command in various formats.

`variant export binary SRC CMD` generates an executable binary at the path `CMD` from your command defined under the
directory `SRC`:

```console
$ variant export binary ./ build/myapp
```

The exported executable binary accepts the same arguments as `variant run`.
So `myapp -h` corresponds to `cd $SRC; variant run -h`, while
`myapp run deploy` corresponds to `cd $SRC; variant run deploy`.

`variant export go SRC/CMD PKG` generates a directory at `PKG/CMD` that contains Go source files that can be built by
running `go build PKG/CMD`.

Assuming you already have `go` installed, you can run `variint export go src/myapp build`, then edit code under
`build/myapp` to make any customization that can't be done with [shims](#generating-shims), and finally build
an executable with `go build -o myapp ./build/myapp`.

## Running Command From Other Directory

Usually, when your command has been defined under the directory `path/to/your/command`, `variant run` requires you to `chdir` to
it before running.

To be clear, `cd $SRC; variant run` can be used to run it from another directory. However with that you command cannot
access the actual current directory, as you've already `cd`ed.

You can also use a [shim](#generating-shims) or an [exported binary](#compiling-command) to make it runnable from any
directory. But it takes some time so probably you'd like to run it from any directory without a `variant export` step
while developing?

The `VARIANT_DIR` environment variable might be the solution. When `variant` recognizes it, it reads the command from the directory
specified by it.

Just run:

```console
VARIANT_DIR=$SRC variant run
```

Your command can now be run without `cd` and still has access to the current directory.

## Split, Merge and Import

Do you have a huge `yourcmd.variant` that needs to be split for readability?
Expand Down

0 comments on commit eed652c

Please sign in to comment.