Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Aug 17, 2016
1 parent 9e19a3e commit 46eff91
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 11 deletions.
5 changes: 3 additions & 2 deletions antibody.go
Expand Up @@ -25,9 +25,9 @@ func New(home string, lines []string) *Antibody {

// Bundle processes all given lines and returns the shell content to execute
func (a *Antibody) Bundle() (string, error) {
var shs []string
var total = len(a.Lines)
var count int
var total = len(a.Lines)
var shs []string
done := make(chan bool)

for _, line := range a.Lines {
Expand All @@ -38,6 +38,7 @@ func (a *Antibody) Bundle() (string, error) {
done <- true
}(line)
}

for {
select {
case event := <-a.Events:
Expand Down
19 changes: 14 additions & 5 deletions cmd/antibody/command/list.go
@@ -1,16 +1,25 @@
package command

import "github.com/urfave/cli"
import (
"fmt"

"github.com/caarlos0/gohome"
"github.com/getantibody/antibody/project"
"github.com/urfave/cli"
)

// List all downloaded bundles
var List = cli.Command{
Name: "list",
Usage: "list all currently downloaded bundles",
Action: func(ctx *cli.Context) error {
// TODO
// for _, b := range bundle.List(antibody.Home()) {
// fmt.Println(b.Name())
// }
projects, err := project.List(gohome.Cache("antibody"))
if err != nil {
return err
}
for _, b := range projects {
fmt.Println(b)
}
return nil
},
}
10 changes: 6 additions & 4 deletions cmd/antibody/command/update.go
@@ -1,14 +1,16 @@
package command

import "github.com/urfave/cli"
import (
"github.com/caarlos0/gohome"
"github.com/getantibody/antibody/project"
"github.com/urfave/cli"
)

// Update all previously bundled bundles
var Update = cli.Command{
Name: "update",
Usage: "updates all previously bundled commands",
Action: func(ctx *cli.Context) error {
// TODO
// antibody.New(bundle.List(antibody.Home())).Update()
return nil
return project.Update(gohome.Cache("antibody"))
},
}
22 changes: 22 additions & 0 deletions project/project.go
@@ -1,8 +1,30 @@
package project

import "io/ioutil"

// Project is basically any kind of project (git, local, svn, bzr, nfs...)
type Project interface {
Download() error
Update() error
Folder() string
}

// List all projects in the given folder
func List(home string) ([]string, error) {
var result []string
entries, err := ioutil.ReadDir(home)
if err != nil {
return result, err
}
for _, entry := range entries {
if entry.Mode().IsDir() && entry.Name()[0] != '.' {
result = append(result, entry.Name())
}
}
return result, nil
}

// Update all projects in the given folder
func Update(home string) error {
return nil
}
39 changes: 39 additions & 0 deletions project/project_test.go
@@ -0,0 +1,39 @@
package project_test

import (
"os"
"testing"

"github.com/getantibody/antibody/project"
"github.com/stretchr/testify/assert"
)

func TestList(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
assert.NoError(project.NewGit(home, "caarlos0/jvm", "gh-pages").Download())
list, err := project.List(home)
assert.NoError(err)
assert.Len(list, 1)
}

func TestListEmptyFolder(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
list, err := project.List(home)
assert.NoError(err)
assert.Len(list, 0)
}

func TestListNonExistentFolder(t *testing.T) {
assert := assert.New(t)
list, err := project.List("/tmp/asdasdadadwhateverwtff")
assert.Error(err)
assert.Len(list, 0)
}

func TestUpdateUpdate(t *testing.T) {
assert.Nil(t, project.Update(""))
}

0 comments on commit 46eff91

Please sign in to comment.