Changed Commander to use []byte over io.Writer

This commit breaks the Commander interface. Prior to this, the Run
method would take in an io.Writer and do its tasks in the background.
Although this has lots of potential for usages, it is also very
overkill. Moreover, it makes IPC harder, since it now has to send over
fragments of data in synchronized order.

This commit gets rid of the io.Writer and only take a []byte for return
along with the error. This makes it easier for both the frontend and
backend to implement most commands, as well as making it easier for data
to be transferred over the wire.
This commit is contained in:
diamondburned 2020-10-13 22:22:02 -07:00
parent 1dd36e0034
commit 05f8ec0cbf
2 changed files with 12 additions and 11 deletions

View File

@ -252,15 +252,16 @@ type Backlogger interface {
// are not in cchat through a very basic terminal interface.
type Commander interface {
// Run executes the given command, with the slice being already split arguments,
// similar to os.Args. The function could return an output stream, in which the
// frontend must display it live and close it on EOF.
// similar to os.Args. The function can return both a []byte and an error value.
// The frontend should render the byte slice's value first, then display the
// error.
//
// The function can do IO, and outputs should be written to the given io.Writer.
// This function can do IO.
//
// The client should make guarantees that an empty string (and thus a
// zero-length string slice) should be ignored. The backend should be able to
// assume that the argument slice is always length 1 or more.
Run([]string, io.Writer) error // Blocking
Run(words []string) ([]byte, error) // Blocking
// Asserters.

View File

@ -851,23 +851,23 @@ var Main = Packages{
Comment: Comment{`
Run executes the given command, with the slice being
already split arguments, similar to os.Args. The
function could return an output stream, in which the
frontend must display it live and close it on EOF.
function can return both a []byte and an error
value. The frontend should render the byte slice's
value first, then display the error.
The function can do IO, and outputs should be
written to the given io.Writer.
This function can do IO.
The client should make guarantees that an empty
string (and thus a zero-length string slice) should
be ignored. The backend should be able to assume
be ignored. The backend should be able to assume
that the argument slice is always length 1 or more.
`},
Name: "Run",
},
Parameters: []NamedType{
{Type: "[]string"},
{Type: "io.Writer"},
{Name: "words", Type: "[]string"},
},
ReturnValue: NamedType{Type: "[]byte"},
ReturnError: true,
},
AsserterMethod{ChildType: "Completer"},