Code Monkey home page Code Monkey logo

go-capturer's People

Contributors

alok87 avatar zenizh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-capturer's Issues

Add capture method selector

Since has shown in #7, we need to drain the buffer to do not block the A operation when full.

We should permit user to select another implementation to overcome this limitation.
This can maybe done with a new goroutine which read and backup data from the pipe.

Readability Fixes

Made some minor changes in the package to made it more readable.

I have kept the changes in https://github.com/alok87/go-capture

  • So that it reads like capture.Stdout instead of capturer.CaptureStdout
  • Minor changes in test

Let me know if you are open for contribution, then we can release it here, but those are backward incompatible. So may need a version up.

Docs is not clear about limit

Since capture is implemented with a pipe, write are blocked when the buffer is full.
But this is not explicitly written inside the documentation.

This doesn't seem to be working for me or doesn't work with struct methods or something:

THis does not work, output is always "":

My struct and method:

type SDCInstanceOutput []scaleio.SdcInstance

// Output - filter results per cli options then output in the correct format
func (i *SDCInstanceOutput) Output(ctx *cli.Context) {
	var filtered SDCInstanceOutput
	for _, row := range *i {
		if ctx.IsSet(FlagNameClientStatus) && strings.Compare(ctx.String(FlagNameClientStatus), "all") != 0 {
			if strings.Compare(ctx.String(FlagNameClientStatus), strings.ToLower(row.MdmConnectionState)) != 0 {
				continue
			}
		}
		filtered = append(filtered, row)
	}
	switch strings.ToLower(ctx.String(FlagNameOutputMode)) {
	case "csv":
		filtered.CSV()
	case "human":
		filtered.Tabular()
	case "json":
		filtered.JSON(ctx)
	default:
		log.Fatalf("ERROR: invalid mode %q", ctx.String(FlagNameOutputMode))
	}
}

Here is where Im trying to write a test, so using a test command like so. output is always "" even though the function is outputting 3 lines of text:

		app.Commands = []*cli.Command{
			&cli.Command{
				Name:        "test-cmd",
				Flags:       []cli.Flag{FlagClientStatus, FlagOutputMode},
				Action: func(x *cli.Context) error {
					output = capturer.CaptureOutput(func() {
						c.givenResult.Output(x)
					})
					log.Infof("OUTPUT=%s", output)
					return nil
				},
			},
		}

		if err := app.Run(c.givenArgs); err != nil {
			t.Fatal(err)
		}

		resultCount := lineCount(output)
		if c.wantedRows != resultCount {
			t.Errorf("expecting %d results, got %d", c.wantedRows, resultCount)
		}
% go test  -v
=== RUN   TestSDCInstanceOutput_Output
Name  IP  Active Version  Installed Version  OS Type  Kernel  Status
                                                              Connected
                                                              Connected
time="2021-09-10T16:57:24.084735-05:00" level=info file="commands_test.go" line=61 msg="OUTPUT="
    commands_test.go:73: expecting 2 results, got 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.