command: init works at a basic level

This commit is contained in:
Mitchell Hashimoto 2014-09-26 16:30:49 -07:00
parent 6cbadf14df
commit f4cc2c066f
3 changed files with 22 additions and 17 deletions

View File

@ -3,7 +3,6 @@ package command
import (
"flag"
"fmt"
"io/ioutil"
"os"
"strings"
@ -50,6 +49,14 @@ func (c *InitCommand) Run(args []string) int {
source := args[0]
// Get our pwd since we need it
pwd, err := os.Getwd()
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error reading working directory: %s", err))
return 1
}
// Verify the directory is empty
if empty, err := config.IsEmptyDir(path); err != nil {
c.Ui.Error(fmt.Sprintf(
@ -63,17 +70,16 @@ func (c *InitCommand) Run(args []string) int {
return 1
}
// Create a temporary directory to store our module
td, err := ioutil.TempDir("", "tf")
// Detect
source, err = module.Detect(source, pwd)
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error creating temporary directory: %s", err))
"Error with module source: %s", err))
return 1
}
defer os.RemoveAll(td)
// Get it!
if err := module.Get(td, source); err != nil {
if err := module.GetCopy(path, source); err != nil {
c.Ui.Error(err.Error())
return 1
}

View File

@ -1,15 +1,18 @@
package command
import (
"os"
"path/filepath"
"testing"
"github.com/mitchellh/cli"
)
/*
func TestGet(t *testing.T) {
func TestInit(t *testing.T) {
dir := tempDir(t)
ui := new(cli.MockUi)
c := &GetCommand{
c := &InitCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -17,21 +20,17 @@ func TestGet(t *testing.T) {
}
args := []string{
testFixturePath("get"),
testFixturePath("init"),
dir,
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
output := ui.OutputWriter.String()
if !strings.Contains(output, "Get: file://") {
t.Fatalf("doesn't look like get: %s", output)
}
if strings.Contains(output, "(update)") {
t.Fatalf("doesn't look like get: %s", output)
if _, err := os.Stat(filepath.Join(dir, "hello.tf")); err != nil {
t.Fatalf("err: %s", err)
}
}
*/
func TestInit_multipleArgs(t *testing.T) {
ui := new(cli.MockUi)

View File