From 05f8ec0cbfc92189b007156f79ce19c45581e49f Mon Sep 17 00:00:00 2001 From: diamondburned Date: Tue, 13 Oct 2020 22:22:02 -0700 Subject: [PATCH] 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. --- cchat.go | 9 +++++---- repository/main.go | 14 +++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cchat.go b/cchat.go index f90cde0..5151cd2 100644 --- a/cchat.go +++ b/cchat.go @@ -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. diff --git a/repository/main.go b/repository/main.go index 4ebe050..b93c6e2 100644 --- a/repository/main.go +++ b/repository/main.go @@ -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"},