Skip to content

Commit

Permalink
Adding ability to handle debugging plugins. (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
shawn-hurley authored Sep 27, 2021
1 parent 29e13f0 commit fb7d4eb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 2 additions & 3 deletions transform/binary-plugin/binary_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ type BinaryPlugin struct {
}

// NewBinaryPlugin -
func NewBinaryPlugin(path string) (transform.Plugin, error) {
func NewBinaryPlugin(path string, logger *logrus.Logger) (transform.Plugin, error) {

commandRunner := &binaryRunner{pluginPath: path}
log := logrus.New().WithField("pluginPath", path)
log := logger.WithField("pluginPath", path)

out, errBytes, err := commandRunner.Metadata(log)
// TODO: Create specific error for command not being run.
Expand Down Expand Up @@ -166,6 +166,5 @@ func (b *binaryRunner) Run(u *unstructured.Unstructured, extras map[string]strin
log.Errorf("unable to run the plugin binary")
return nil, nil, fmt.Errorf("unable to run the plugin binary, err: %v", err)
}

return out.Bytes(), errorBytes.Bytes(), nil
}
2 changes: 1 addition & 1 deletion transform/binary-plugin/binary_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func TestNewBinaryPlugin(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cliContext = tt.cliContext
b, err := NewBinaryPlugin(tt.name)
b, err := NewBinaryPlugin(tt.name, logrus.New())
if (err != nil) != tt.wantErr {
t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
7 changes: 5 additions & 2 deletions transform/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
stdOut io.Writer
reader io.Reader
exiter func(int)
logger *logrus.Logger
)

func init() {
Expand All @@ -28,6 +29,8 @@ func init() {
reader = os.Stdin

exiter = os.Exit
logger = logrus.New()
logger.SetOutput(stdErr)
}

type customPlugin struct {
Expand Down Expand Up @@ -66,8 +69,8 @@ func WriterErrorAndExit(err error) {
exiter(1)
}

func Logger() logrus.FieldLogger {
return &logrus.Logger{}
func Logger() *logrus.Logger {
return logger
}

func RunAndExit(plugin transform.Plugin) {
Expand Down

0 comments on commit fb7d4eb

Please sign in to comment.