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. // are not in cchat through a very basic terminal interface.
type Commander interface { type Commander interface {
// Run executes the given command, with the slice being already split arguments, // 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 // similar to os.Args. The function can return both a []byte and an error value.
// frontend must display it live and close it on EOF. // 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 // 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 // zero-length string slice) should be ignored. The backend should be able to
// assume that the argument slice is always length 1 or more. // assume that the argument slice is always length 1 or more.
Run([]string, io.Writer) error // Blocking Run(words []string) ([]byte, error) // Blocking
// Asserters. // Asserters.

View File

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