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

Commit

Permalink
Merge pull request #178 from getantibody/cobra
Browse files Browse the repository at this point in the history
Replaced cli with cobra
  • Loading branch information
caarlos0 authored May 5, 2017
2 parents ccaadc8 + 0cc5f3f commit 83893d2
Show file tree
Hide file tree
Showing 24 changed files with 226 additions and 181 deletions.
34 changes: 23 additions & 11 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@

[[dependencies]]
name = "github.com/getantibody/folder"
version = "v1.0.0"

[[dependencies]]
name = "github.com/stretchr/testify"
version = "^1.1.4"

[[dependencies]]
name = "github.com/urfave/cli"
version = "^1.19.1"

[[dependencies]]
branch = "master"
name = "golang.org/x/crypto"

[[dependencies]]
branch = "master"
name = "golang.org/x/sync"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ lint: ## Run all the linters
ci: lint test ## Run all the tests and code checks

build: ## Build a beta version
go build -o goreleaser ./cmd/antibody/main.go
go build

# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
Expand Down
2 changes: 1 addition & 1 deletion antibody.go → antibodylib/antibody.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package antibody
package antibodylib

import (
"bufio"
Expand Down
12 changes: 6 additions & 6 deletions antibody_test.go → antibodylib/antibody_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package antibody_test
package antibodylib_test

import (
"bytes"
Expand All @@ -7,7 +7,7 @@ import (
"strings"
"testing"

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

Expand All @@ -24,7 +24,7 @@ func TestAntibody(t *testing.T) {
" # trick play",
"/tmp kind:path",
}
sh, err := antibody.New(
sh, err := antibodylib.New(
home,
bytes.NewBufferString(strings.Join(bundles, "\n")),
).Bundle()
Expand All @@ -42,18 +42,18 @@ func TestAntibodyError(t *testing.T) {
assert := assert.New(t)
home := home()
bundles := bytes.NewBufferString("invalid-repo")
sh, err := antibody.New(home, bundles).Bundle()
sh, err := antibodylib.New(home, bundles).Bundle()
assert.Error(err)
assert.Empty(sh)
}

func TestHome(t *testing.T) {
assert.Contains(t, antibody.Home(), "antibody")
assert.Contains(t, antibodylib.Home(), "antibody")
}

func TestHomeFromEnvironmentVariable(t *testing.T) {
assert.NoError(t, os.Setenv("ANTIBODY_HOME", "/tmp"))
assert.Equal(t, "/tmp", antibody.Home())
assert.Equal(t, "/tmp", antibodylib.Home())
}

func home() string {
Expand Down
4 changes: 4 additions & 0 deletions antibodylib/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package antibodylib

// Version is antibody's version
var Version = "dev"
2 changes: 1 addition & 1 deletion sort.go → antibodylib/sort.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package antibody
package antibodylib

import (
"sort"
Expand Down
35 changes: 0 additions & 35 deletions cmd/antibody/command/bundle.go

This file was deleted.

19 changes: 0 additions & 19 deletions cmd/antibody/command/home.go

This file was deleted.

19 changes: 0 additions & 19 deletions cmd/antibody/command/init.go

This file was deleted.

27 changes: 0 additions & 27 deletions cmd/antibody/command/list.go

This file was deleted.

19 changes: 0 additions & 19 deletions cmd/antibody/command/update.go

This file was deleted.

26 changes: 0 additions & 26 deletions cmd/antibody/main.go

This file was deleted.

37 changes: 37 additions & 0 deletions cmd/bundle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"bytes"
"fmt"
"io"
"os"
"strings"

"github.com/getantibody/antibody/antibodylib"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)

var bundleCmd = &cobra.Command{
Use: "bundle",
Aliases: []string{"b"},
Short: "downloads a bundle and prints its source line",
RunE: func(cmd *cobra.Command, args []string) error {
var input io.Reader
if !terminal.IsTerminal(int(os.Stdin.Fd())) && len(args) == 0 {
input = os.Stdin
} else {
input = bytes.NewBufferString(strings.Join(args, " "))
}
sh, err := antibodylib.New(antibodylib.Home(), input).Bundle()
if err != nil {
return err
}
fmt.Println(sh)
return nil
},
}

func init() {
RootCmd.AddCommand(bundleCmd)
}
21 changes: 21 additions & 0 deletions cmd/home.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"fmt"

"github.com/getantibody/antibody/antibodylib"
"github.com/spf13/cobra"
)

var homeCmd = &cobra.Command{
Use: "home",
Short: "shows the current antibody home folder",
Aliases: []string{"prefix", "p"},
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(antibodylib.Home())
},
}

func init() {
RootCmd.AddCommand(homeCmd)
}
Loading

0 comments on commit 83893d2

Please sign in to comment.