This repository has been archived by the owner on May 27, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("")) | ||
} |