#variant (2019-07)
Discuss variant (the “Universal CLI”) https://github.com/mumoshu/variant
Archive: https://archive.sweetops.com/variant/
2019-07-02

When releasing a variant
made command has anyone run into:
./main.go:4:5: undefined: cmd.YAML


updated Gopkg.toml
to version = "v0.31.1"
and re-ran dep ensure

currently waiting for that complete.


2019-07-16

Deliver Go binaries as fast and easily as possible

Has anyone tried to marry variant and goreleaser? I love the idea of automatically building the binary and updating homebrew.
2019-07-17

are there any examples for how to integrate https://github.com/davidovich/summon with variant?
Summon: your data on caffeine. Contribute to davidovich/summon development by creating an account on GitHub.

I’m looking to include additional shell scripts in the variant binary vs trying to write out the each full script within the variant config.

cc @Erik Osterman (Cloud Posse) wondering if you’ve run into this before

Aha yes @mumoshu has somethings he is working on for this

I think one is called mod

I am away right now but will look it up

Package manager for Makefile and Variantfile. Any set of files in Git/S3/GCS/HTTP as a reusable and parameterized module - variantdev/mod

I was looking at this and reading the Slack archives but didn’t realize it could be used with shell scripts.

SweetOps is a collaborative DevOps community. We welcome engineers from around the world of all skill levels, backgrounds, and experience to join us! This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build sweet infrastructure.
2019-07-25

@davidvasandani Hey! I understand your use-case but unfortunately we don’t yet have an example

If I could figure out how to get started I’d be happy to contribute one.

You can add some go code to the go source output by variant build
but

I’m using variant in a couple different projects but all my shellscripts are in a single variant yaml file

Perhaps you’d prefer easier ways, like you add a few lines to your variant command yaml and variant build
to get the bundled binary..?

Exactly.


bundle:
files:
- ./utils.sh
- ./helpers.sh
tasks:
foo:
script: |
{{.moduleDir}}/utils.sh myutilfunc arg1 arg2

exactly this.

Good. I’ll try implementing it soon

In the meantime, you’ll be able to integrate summon like this:
package main
import (
"fmt"
"os"
)
func main() {
assetsDir := "assets"
box := packr.New("Bundled Assets", assetsDir)
summoner, err := summon.New(r.box)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
msg, err := r.s.Summon(
summon.All(true),
summon.Raw(true),
summon.Dest(assetsDir),
)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("summon: %s\n", msg)
// Inject go code generated by `variant build` here...
}

And in your script
call it like assets/utils.sh myutilfunc arg1 arg2
.
packr2
bundles all the files under assets
and summon extracts em into assets

2019-07-26

I’ve added summon
and packr2
but these are the errors I get when I build:
./main.go:16:30: undefined: r
./main.go:22:14: undefined: r

Whats r
and s
on this line ` msg, err := r.s.Summon(`
2019-07-27

Ah sry that’s a copypaste issue. Replace r.s
with summoner

./main.go:16:31: undefined: r
./main.go:22:23: cannot call non-function summoner (type *summon.Driver)

@mumoshu This is my main.go
file:

package main
import (
"fmt"
"os"
"github.com/mumoshu/variant/cmd"
"github.com/gobuffalo/packr/v2"
"github.com/davidovich/summon/pkg/summon"
)
func main() {
assetsDir := "assets"
box := packr.New("Bundled Assets", assetsDir)
summoner, err := summon.New(r.box)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
msg, err := summoner(
summon.All(true),
summon.Raw(true),
summon.Dest(assetsDir),
)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("summon: %s\n", msg)
cmd.YAML(`
#!/usr/bin/env variant
tasks:
hello:
script: |
echo Hello $(whoami)!
whoami:
script: |
assets/whoami.sh
`)
}

summon.New(r.box)
should be summon.New(box)

and msg, err := summoner(
should be msg, err := summoner.Summon(

thanks! testing now.

Do you recommend I inject the output of variant build ...
or use cmd.YAML
and inject the output of the variant file?

either is okay!

When you responded I was using variant build


this is the latest main.go

./main.go:36:17: *variant.TaskDef literal evaluated but not used
./main.go:36: unknown field 'fun' in struct literal of type variant.TaskDef

I’ll push up my example.

Contribute to davidneudorfer/variant-assets-example development by creating an account on GitHub.
2019-07-28

@mumoshu any suggestions to help get me unstuck?

yep. this example will help https://github.com/mumoshu/variant/blob/master/examples/hello/hack/generate-maingo-struct
Wrap up your bash scripts into a modern CLI today. Graduate to a full-blown golang app tomorrow. - mumoshu/variant

basically you need to pass the variant build output into a golang func call of variant.Def()


./main.go:35:3: undefined: variant.Def
./main.go:36: unknown field 'fun' in struct literal of type variant.TaskDef

@mumoshu this is the error I get with the following main.go


Try removing references to fun
fields like fun:(func(variant.ExecutionContext) (string, error))(nil)}},
from your code

And does changing "[github.com/mumoshu/variant/pkg](http://github.com/mumoshu/variant/pkg)"
to variant "[github.com/mumoshu/variant/pkg](http://github.com/mumoshu/variant/pkg)"
in your import ( )
make difference to you?

./main.go:38:2: syntax error: unexpected ), expecting expression
./main.go:40:2: syntax error: unexpected newline, expecting comma or )


You seem to have missed closing parenthesis(es) on the way. Do you have VisualStudio Code or something that highlight suspicious parts of your code?