#variant (2019-07)

https://github.com/mumoshu/variant

Discuss variant (the “Universal CLI”) https://github.com/mumoshu/variant

Archive: https://archive.sweetops.com/variant/

2019-07-02

davidvasandani avatar
davidvasandani

When releasing a variant made command has anyone run into:

./main.go:4:5: undefined: cmd.YAML
mumoshu avatar
mumoshu

would you mind sharing the full log?

1
davidvasandani avatar
davidvasandani

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

davidvasandani avatar
davidvasandani

currently waiting for that complete.

davidvasandani avatar
davidvasandani

Everything works

1
davidvasandani avatar
davidvasandani

Thanks @mumoshu

1

2019-07-16

davidvasandani avatar
davidvasandani
GoReleaser

Deliver Go binaries as fast and easily as possible

davidvasandani avatar
davidvasandani

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

2019-07-17

davidvasandani avatar
davidvasandani

are there any examples for how to integrate https://github.com/davidovich/summon with variant?

davidovich/summon

Summon: your data on caffeine. Contribute to davidovich/summon development by creating an account on GitHub.

davidvasandani avatar
davidvasandani

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.

davidvasandani avatar
davidvasandani

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

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

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

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

I think one is called mod

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

I am away right now but will look it up

davidvasandani avatar
davidvasandani
variantdev/mod

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

davidvasandani avatar
davidvasandani

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

davidvasandani avatar
davidvasandani
variant

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

mumoshu avatar
mumoshu

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

1
davidvasandani avatar
davidvasandani

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

mumoshu avatar
mumoshu

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

davidvasandani avatar
davidvasandani

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

1
mumoshu avatar
mumoshu

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..?

davidvasandani avatar
davidvasandani

Exactly.

mumoshu avatar
mumoshu

Great. So I was considering to enhance variant or mod to cover that

1
mumoshu avatar
mumoshu
bundle:
  files:
  - ./utils.sh
 - ./helpers.sh

tasks:
  foo:
    script: |
      {{.moduleDir}}/utils.sh myutilfunc arg1 arg2
1
davidvasandani avatar
davidvasandani

exactly this.

mumoshu avatar
mumoshu

Good. I’ll try implementing it soon

mumoshu avatar
mumoshu

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...
}
mumoshu avatar
mumoshu

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

davidvasandani avatar
davidvasandani

I’ll give this a shot. Thanks @mumoshu

1

2019-07-26

davidvasandani avatar
davidvasandani

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
davidvasandani avatar
davidvasandani

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

2019-07-27

mumoshu avatar
mumoshu

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

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

@mumoshu This is my main.go file:

davidvasandani avatar
davidvasandani
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
	`)
}
mumoshu avatar
mumoshu

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

mumoshu avatar
mumoshu

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

davidvasandani avatar
davidvasandani

thanks! testing now.

davidvasandani avatar
davidvasandani

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

mumoshu avatar
mumoshu

either is okay!

davidvasandani avatar
davidvasandani

When you responded I was using variant build

davidvasandani avatar
davidvasandani
davidvasandani avatar
davidvasandani

this is the latest main.go

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

I’ll push up my example.

davidvasandani avatar
davidvasandani
davidneudorfer/variant-assets-example

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

2019-07-28

davidvasandani avatar
davidvasandani

@mumoshu any suggestions to help get me unstuck?

mumoshu avatar
mumoshu
mumoshu/variant

Wrap up your bash scripts into a modern CLI today. Graduate to a full-blown golang app tomorrow. - mumoshu/variant

mumoshu avatar
mumoshu

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

davidvasandani avatar
davidvasandani

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

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

davidvasandani avatar
davidvasandani
mumoshu avatar
mumoshu

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

mumoshu avatar
mumoshu

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?

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

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?

    keyboard_arrow_up