Remove dead code related to old plugin method

This commit is contained in:
Ian Howell 2019-05-17 14:01:17 -05:00
parent c89bd79342
commit 34d0ff7e4d
10 changed files with 9 additions and 92 deletions

View File

@ -3,8 +3,8 @@ package cmd
import (
"io"
// "github.com/ian-howell/exampleplugin"
"github.com/spf13/cobra"
"github.com/ian-howell/exampleplugin"
)
// builtinPlugins are the plugins that are built and maintained by the
@ -16,5 +16,5 @@ var builtinPlugins = []func(io.Writer, []string) *cobra.Command{
// externalPlugins are external. The function to create a command should be
// placed here
var externalPlugins = []func(io.Writer, []string) *cobra.Command{
exampleplugin.NewExampleCommand, // This is an example and shouldn't be enabled in production builds
// exampleplugin.NewExampleCommand, // This is an example and shouldn't be enabled in production builds
}

View File

@ -5,10 +5,10 @@ import (
"io"
"os"
"github.com/spf13/cobra"
"github.com/ian-howell/airshipctl/pkg/environment"
"github.com/ian-howell/airshipctl/pkg/log"
"github.com/spf13/cobra"
)
var settings environment.AirshipCTLSettings

View File

@ -4,7 +4,6 @@ Usage:
airshipctl [command]
Available Commands:
example an example command
help Help about any command
version Show the version number of airshipctl
workflow access to workflows

View File

@ -8,6 +8,7 @@ import (
var kubeConfigFilePath string
// NewWorkflowCommand creates a new command for working with argo workflows
func NewWorkflowCommand(out io.Writer, args []string) *cobra.Command {
workflowRootCmd := &cobra.Command{
Use: "workflow",

View File

@ -13,6 +13,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
)
// NewWorkflowListCommand is a command for listing argo workflows
func NewWorkflowListCommand(out io.Writer, args []string) *cobra.Command {
// TODO(howell): This is only used to appease the linter. It will be used later

View File

@ -21,11 +21,13 @@ const (
goldenFileSuffix = ".golden"
)
// CmdTest is a command to be run on the command line as a test
type CmdTest struct {
Name string
Command string
}
// RunCmdTests checks all of the tests actual output against their expected outputs
func RunCmdTests(t *testing.T, tests []CmdTest) {
t.Helper()
for _, test := range tests {

View File

@ -1,28 +0,0 @@
package plugin
import (
"fmt"
"io"
"plugin"
"github.com/spf13/cobra"
)
const badInterfaceFormat = `plugin at %s is missing required function:
- NewCommand(func io.writer, []string) *cobra.Command)`
func CreateCommandFromPlugin(pluginPath string, out io.Writer, args []string) (*cobra.Command, error) {
plug, err := plugin.Open(pluginPath)
if err != nil {
return nil, fmt.Errorf("plugin at %s could not be opened", pluginPath)
}
cmdSym, err := plug.Lookup("NewCommand")
if err != nil {
return nil, fmt.Errorf(badInterfaceFormat, pluginPath)
}
command, ok := cmdSym.(func(io.Writer, []string) *cobra.Command)
if !ok {
return nil, fmt.Errorf(badInterfaceFormat, pluginPath)
}
return command(out, args), nil
}

View File

@ -12,13 +12,3 @@ func IsReadable(path string) error {
}
return f.Close()
}
// ReadDir does the same thing as ioutil.ReadDir, but it doesn't sort the files.
func ReadDir(dirname string) ([]os.FileInfo, error) {
f, err := os.Open(dirname)
if err != nil {
return []os.FileInfo{}, err
}
defer f.Close()
return f.Readdir(-1)
}

View File

@ -3,7 +3,6 @@ package util_test
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/ian-howell/airshipctl/pkg/util"
@ -39,51 +38,3 @@ func TestIsReadable(t *testing.T) {
t.Errorf("Expected '%s' error, got '%s'", expected, err.Error())
}
}
func TestReadDir(t *testing.T) {
dir, err := ioutil.TempDir("", "airshipctl-tests")
if err != nil {
t.Fatalf("Could not create a temporary directory: %s", err.Error())
}
defer os.RemoveAll(dir)
testFiles := []string{
"test1.txt",
"test2.txt",
"test3.txt",
}
for _, testFile := range testFiles {
if err := ioutil.WriteFile(filepath.Join(dir, testFile), []byte("testdata"), 0666); err != nil {
t.Fatalf("Could not create test file '%s': %s", testFile, err.Error())
}
}
files, err := util.ReadDir(dir)
if err != nil {
t.Fatalf("Unexpected error while reading directory: %s", err.Error())
}
if len(files) != len(testFiles) {
t.Errorf("Expected %d files, got %d", len(testFiles), len(files))
}
for _, testFile := range testFiles {
found := false
for _, actualFile := range files {
if testFile == actualFile.Name() {
found = true
break
}
}
if !found {
t.Errorf("Could not find test file '%s'", testFile)
}
}
os.RemoveAll(dir)
if _, err := util.ReadDir(dir); err == nil {
t.Error("Expected an error when reading non-existant directory")
}
}

View File

@ -3,6 +3,7 @@
package tools
import (
// These imports are all tools used in the building and testing process
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/shuLahn/go-bindata/cmd/go-bindata"
)