#variant - July 2019

variantArchived
43 messages

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

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

davidvasandani
davidvasandaniover 7 years ago
When releasing a variant made command has anyone run into:

./main.go:4:5: undefined: cmd.YAML
davidvasandani
davidvasandaniover 7 years ago
davidvasandani
davidvasandaniover 7 years ago
Has anyone tried to marry variant and goreleaser? I love the idea of automatically building the binary and updating homebrew.
davidvasandani
davidvasandaniover 7 years ago
are there any examples for how to integrate https://github.com/davidovich/summon with variant?
davidvasandani
davidvasandaniover 7 years ago
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
davidvasandaniover 7 years ago
cc @Erik Osterman (Cloud Posse) wondering if you’ve run into this before ☝️🏻
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)over 7 years ago
Aha yes @mumoshu has somethings he is working on for this
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)over 7 years ago
I think one is called mod
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)over 7 years ago
I am away right now but will look it up
davidvasandani
davidvasandaniover 7 years ago
davidvasandani
davidvasandaniover 7 years ago
I was looking at this and reading the Slack archives but didn’t realize it could be used with shell scripts.
mumoshu
mumoshuover 7 years ago
@davidvasandani Hey! I understand your use-case but unfortunately we don't yet have an example
davidvasandani
davidvasandaniover 7 years ago
If I could figure out how to get started I’d be happy to contribute one.
mumoshu
mumoshuover 7 years ago
You can add some go code to the go source output by variant build but
davidvasandani
davidvasandaniover 7 years ago
I’m using variant in a couple different projects but all my shellscripts are in a single variant yaml file 😳
mumoshu
mumoshuover 7 years ago
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
davidvasandaniover 7 years ago
Exactly.
mumoshu
mumoshuover 7 years ago
Great. So I was considering to enhance variant or mod to cover that
mumoshu
mumoshuover 7 years ago(edited)

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

tasks:
  foo:
    script: |
      {{.moduleDir}}/utils.sh myutilfunc arg1 arg2
davidvasandani
davidvasandaniover 7 years ago
☝️🏻 exactly this.
mumoshu
mumoshuover 7 years ago
Good. I'll try implementing it soon 😃
mumoshu
mumoshuover 7 years ago
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
mumoshuover 7 years ago
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
davidvasandaniover 7 years ago
I’ll give this a shot. Thanks @mumoshu 🎉
davidvasandani
davidvasandaniover 7 years ago(edited)
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
davidvasandaniover 7 years ago
Whats r and s on this line msg, err := r.s.Summon(
mumoshu
mumoshuover 7 years ago
Ah sry that's a copypaste issue. Replace r.s with summoner
davidvasandani
davidvasandaniover 7 years ago

./main.go:16:31: undefined: r
./main.go:22:23: cannot call non-function summoner (type *summon.Driver)
davidvasandani
davidvasandaniover 7 years ago(edited)
@mumoshu This is my main.go file:
davidvasandani
davidvasandaniover 7 years ago

package main

import (
	"fmt"
	"os"
  "<http://github.com/mumoshu/variant/cmd|github.com/mumoshu/variant/cmd>"
  "<http://github.com/gobuffalo/packr/v2|github.com/gobuffalo/packr/v2>"
  "<http://github.com/davidovich/summon/pkg/summon|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
mumoshuover 7 years ago
summon.New(r.box) should be summon.New(box)
mumoshu
mumoshuover 7 years ago
and msg, err := summoner( should be msg, err := summoner.Summon(
davidvasandani
davidvasandaniover 7 years ago
thanks! testing now.
davidvasandani
davidvasandaniover 7 years ago
Do you recommend I inject the output of variant build ... or use cmd.YAML and inject the output of the variant file?
davidvasandani
davidvasandaniover 7 years ago
When you responded I was using variant build
davidvasandani
davidvasandaniover 7 years ago
davidvasandani
davidvasandaniover 7 years ago
this is the latest main.go
davidvasandani
davidvasandaniover 7 years ago

./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
davidvasandaniover 7 years ago
I’ll push up my example.
davidvasandani
davidvasandaniover 7 years ago
@mumoshu any suggestions to help get me unstuck?