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

Commit

Permalink
Support for non-antigen-complient plugins
Browse files Browse the repository at this point in the history
like rupa/z and many others.

fixes #29
  • Loading branch information
caarlos0 committed Jun 26, 2015
1 parent 7d07a13 commit f851fb9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
6 changes: 3 additions & 3 deletions antibody.zsh
@@ -1,6 +1,6 @@
#!/bin/zsh
#!/usr/bin/env zsh
ANTIBODY_BINARIES="$(dirname $0)"
mkdir -p "$HOME/.antibody" || true
[[ -n "${ANTIBODY_HOME}" ]] && mkdir -p "${ANTIBODY_HOME}" || mkdir -p "${HOME}/.antibody"

antibody() {
case "$1" in
Expand All @@ -9,7 +9,7 @@ antibody() {
;;
*)
while read bundle; do
source "$bundle"/*.plugin.zsh 2&> /tmp/antibody-log
source "$bundle" 2&> /tmp/antibody-log
done < <( ${ANTIBODY_BINARIES}/bin/antibody $@ )
;;
esac
Expand Down
10 changes: 6 additions & 4 deletions lib/antibody.go
Expand Up @@ -8,19 +8,21 @@ import (
type antibody struct {
bundles []Bundle
}
type bundleAction func(bundle Bundle)
type bundleFn func(bundle Bundle)

func NewAntibody(bundles []Bundle) antibody {
return antibody{bundles}
}

func (a antibody) forEach(fn bundleAction) {
func (a antibody) forEach(fn bundleFn) {
var wg sync.WaitGroup
for _, bundle := range a.bundles {
wg.Add(1)
go func(bundle Bundle, fn bundleAction, wg *sync.WaitGroup) {
go func(bundle Bundle, fn bundleFn, wg *sync.WaitGroup) {
fn(bundle)
fmt.Println(bundle.Folder())
for _, sourceable := range bundle.Sourceables() {
fmt.Println(sourceable)
}
wg.Done()
}(bundle, fn, &wg)
}
Expand Down
3 changes: 2 additions & 1 deletion lib/api_test.go
Expand Up @@ -2,11 +2,12 @@ package antibody

import (
"bytes"
"github.com/caarlos0/antibody/lib/doubles"
"io/ioutil"
"os"
"strings"
"testing"

"github.com/caarlos0/antibody/lib/doubles"
)

func expectError(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions lib/bundle.go
Expand Up @@ -4,4 +4,5 @@ type Bundle interface {
Folder() string
Download() error
Update() error
Sourceables() []string
}
19 changes: 16 additions & 3 deletions lib/git_bundle.go
Expand Up @@ -3,11 +3,10 @@ package antibody
import (
"os"
"os/exec"
"path/filepath"
"strings"
)

const GH = "https://github.com/"

func folder(bundle string, home string) string {
return home + strings.Replace(bundle, "/", "-", -1)
}
Expand All @@ -29,10 +28,24 @@ func (b gitBundle) Folder() string {
return b.folder
}

func (b gitBundle) Sourceables() []string {
globs := [...]string{"*.plugin.zsh", "*.zsh", "*.sh"}
for _, glob := range globs {
files, _ := filepath.Glob(filepath.Join(b.Folder(), glob))
if files != nil {
return files
}
}
return nil
}

type gitBundle struct {
url, folder string
}

func NewGitBundle(bundle, home string) Bundle {
return gitBundle{GH + bundle, folder(bundle, home)}
return gitBundle{
url: "https://github.com/" + bundle,
folder: folder(bundle, home),
}
}
23 changes: 22 additions & 1 deletion lib/git_bundle_test.go
@@ -1,8 +1,9 @@
package antibody

import (
"github.com/caarlos0/antibody/lib/doubles"
"testing"

"github.com/caarlos0/antibody/lib/doubles"
)

func TestClonesValidRepo(t *testing.T) {
Expand Down Expand Up @@ -51,3 +52,23 @@ func TestPullsRepo(t *testing.T) {
t.Error("No errors expected")
}
}

func TestSourceablesDotPluginZsh(t *testing.T) {
home := doubles.TempHome()
bundle := NewGitBundle("caarlos0/zsh-pg", home)
bundle.Download()
srcs := bundle.Sourceables()
if len(srcs) != 1 {
t.Error("Expected 1 sourceable file")
}
}

func TestSourceablesDotSh(t *testing.T) {
home := doubles.TempHome()
bundle := NewGitBundle("rupa/z", home)
bundle.Download()
srcs := bundle.Sourceables()
if len(srcs) != 1 {
t.Error("Expected 1 sourceable file")
}
}

0 comments on commit f851fb9

Please sign in to comment.