2019
Jul

#variant

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

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

2019-07-28

davidvasandani

@mumoshu any suggestions to help get me unstuck?

mumoshu
mumoshu/variant

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

mumoshu

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

davidvasandani

davidvasandani
./main.go<i class="em em-35"></i>3: undefined: variant.Def
./main.go<i class="em em-36"></i> unknown field 'fun' in struct literal of type variant.TaskDef
davidvasandani

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

davidvasandani
mumoshu

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

mumoshu

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

davidvasandani
./main.go<i class="em em-38"></i>2: syntax error: unexpected ), expecting expression
./main.go<i class="em em-40"></i>2: syntax error: unexpected newline, expecting comma or )
davidvasandani
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?

2019-07-27

mumoshu

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

davidvasandani
./main.go<i class="em em-16"></i>31: undefined: r
./main.go<i class="em em-22"></i>23: cannot call non-function summoner (type *summon.Driver)
davidvasandani

@mumoshu This is my main.go file:

davidvasandani
package main

import (
	"fmt"
	"os"
  "<http://github.com/mumoshu/variant/cmd>"
  "<http://github.com/gobuffalo/packr/v2>"
  "<http://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

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

mumoshu

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

davidvasandani

thanks! testing now.

davidvasandani

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

mumoshu

either is okay!

davidvasandani

When you responded I was using variant build

davidvasandani
davidvasandani

this is the latest main.go

davidvasandani
./main.go<i class="em em-36"></i>17: *variant.TaskDef literal evaluated but not used
./main.go<i class="em em-36"></i> unknown field 'fun' in struct literal of type variant.TaskDef
davidvasandani

I’ll push up my example.

davidvasandani
davidneudorfer/variant-assets-example

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

2019-07-26

davidvasandani

I’ve added summon and packr2 but these are the errors I get when I build:

./main.go<i class="em em-16"></i>30: undefined: r
./main.go<i class="em em-22"></i>14: undefined: r
davidvasandani

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

2019-07-25

mumoshu

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

1
davidvasandani

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

mumoshu

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

davidvasandani

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

1
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

Exactly.

mumoshu

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

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

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

exactly this.

mumoshu

Good. I’ll try implementing it soon

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

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

I’ll give this a shot. Thanks @mumoshu

1

2019-07-17

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

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

cc @Erik Osterman wondering if you’ve run into this before

Erik Osterman

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

Erik Osterman

I think one is called mod

Erik Osterman

I am away right now but will look it up

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

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

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-16

davidvasandani
GoReleaser

Deliver Go binaries as fast and easily as possible

davidvasandani

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

2019-07-02

davidvasandani

When releasing a variant made command has anyone run into:

./main.go<i class="em em-4"></i>5: undefined: cmd.YAML
mumoshu

would you mind sharing the full log?

davidvasandani

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

davidvasandani

currently waiting for that complete.

davidvasandani

Everything works

davidvasandani

Thanks @mumoshu

2019
Jul
    keyboard_arrow_up