Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions internal/shell/cmd_compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@ func (c *CompileCommand) compile(compileCmd string, compileArgs ...string) error
if err != nil {
return merry.Wrap(err)
}
genInput := gen.Input{
Imports: c.Imports.Value(),
Replaces: c.Replaces.Value(),
Gets: c.Gets.Value(),
WorkingDir: workingDir,
USQLVersion: c.USQLVersion,
USQLModule: c.USQLModule,
}
genResult, err := c.generator(genInput)
genResult, err := c.generate(workingDir)
if err != nil {
return merry.Wrap(err)
}
Expand All @@ -63,6 +55,18 @@ func (c *CompileCommand) compile(compileCmd string, compileArgs ...string) error
return run.GoBin(workingDir, c.goBin, args...)
}

func (c *CompileCommand) generate(workingDir string) (gen.Result, error) {
genInput := gen.Input{
Imports: c.Imports.Value(),
Replaces: c.Replaces.Value(),
Gets: c.Gets.Value(),
WorkingDir: workingDir,
USQLVersion: c.USQLVersion,
USQLModule: c.USQLModule,
}
return c.generator(genInput)
}

func (c *CompileCommand) MakeFlags() []cli.Flag {
return append([]cli.Flag{
&cli.StringSliceFlag{
Expand Down
23 changes: 23 additions & 0 deletions internal/shell/cmd_generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package shell

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestGenerate(t *testing.T) {
tmpDir := t.TempDir()
t.Run("happy path", func(t *testing.T) {
cmd := GenerateCommand{
CompileCommand: minimalCompileCommand(),
output: tmpDir,
}
err := cmd.Action(nil)
require.NoError(t, err)

require.FileExists(t, filepath.Join(tmpDir, "go.mod"))
})

}
10 changes: 9 additions & 1 deletion internal/shell/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package shell
// Defines commands too short for their own file and the Commands object

import (
"os"

"github.com/ansel1/merry/v2"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -33,7 +36,12 @@ if value is -, tar archive will be written to standard output`,
}

func (c *GenerateCommand) Action(*cli.Context) error {
return c.CompileCommand.compile("")
err := os.MkdirAll(c.output, 0700)
if err != nil {
return merry.Wrap(err)
}
_, err = c.generate(c.output)
return err
}

type Commands struct {
Expand Down
Loading