register csvviewer (#3)

New csvview command
This commit is contained in:
Red J Adaya
2023-10-11 17:59:22 -07:00
committed by GitHub
parent 9b380aee02
commit 50190902ca
4 changed files with 67 additions and 1800 deletions
+7 -9
View File
@@ -5,6 +5,7 @@ go 1.18
require (
github.com/alessio/shellescape v1.4.1
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2
github.com/commandlinedev/apishell v0.0.0
github.com/creack/pty v1.1.18
github.com/golang-migrate/migrate/v4 v4.16.2
github.com/google/uuid v1.3.0
@@ -12,19 +13,16 @@ require (
github.com/gorilla/websocket v1.5.0
github.com/jmoiron/sqlx v1.3.5
github.com/mattn/go-sqlite3 v1.14.16
github.com/sashabaranov/go-openai v1.9.0
github.com/sawka/txwrap v0.1.2
github.com/commandlinedev/apishell v0.0.0
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/mod v0.5.1
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
mvdan.cc/sh/v3 v3.5.1
golang.org/x/crypto v0.7.0
golang.org/x/mod v0.10.0
golang.org/x/sys v0.10.0
mvdan.cc/sh/v3 v3.7.0
)
require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/sashabaranov/go-openai v1.9.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
)
)
+26 -1791
View File
File diff suppressed because it is too large Load Diff
+33
View File
@@ -225,6 +225,8 @@ func init() {
registerCmdFn("imageview", ImageViewCommand)
registerCmdFn("mdview", MarkdownViewCommand)
registerCmdFn("markdownview", MarkdownViewCommand)
registerCmdFn("csvview", CSVViewCommand)
}
func getValidCommands() []string {
@@ -3187,6 +3189,37 @@ func CodeEditCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sst
return update, nil
}
func CSVViewCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
if len(pk.Args) == 0 {
return nil, fmt.Errorf("%s requires an argument (file name)", GetCmdStr(pk))
}
// TODO more error checking on filename format?
if pk.Args[0] == "" {
return nil, fmt.Errorf("%s argument cannot be empty", GetCmdStr(pk))
}
ids, err := resolveUiIds(ctx, pk, R_Session|R_Screen|R_RemoteConnected)
if err != nil {
return nil, err
}
outputStr := fmt.Sprintf("%s %q", GetCmdStr(pk), pk.Args[0])
cmd, err := makeStaticCmd(ctx, GetCmdStr(pk), ids, pk.GetRawStr(), []byte(outputStr))
if err != nil {
// TODO tricky error since the command was a success, but we can't show the output
return nil, err
}
// set the line state
lineState := make(map[string]any)
lineState[sstore.LineState_Source] = "file"
lineState[sstore.LineState_File] = pk.Args[0]
update, err := addLineForCmd(ctx, "/"+GetCmdStr(pk), true, ids, cmd, "csv", lineState)
if err != nil {
// TODO tricky error since the command was a success, but we can't show the output
return nil, err
}
update.Interactive = pk.Interactive
return update, nil
}
func ImageViewCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
if len(pk.Args) == 0 {
return nil, fmt.Errorf("%s requires an argument (file name)", GetCmdStr(pk))
+1
View File
@@ -31,6 +31,7 @@ var BareMetaCmds = []BareMetaCmdDecl{
BareMetaCmdDecl{"imageview", "imageview"},
BareMetaCmdDecl{"markdownview", "markdownview"},
BareMetaCmdDecl{"mdview", "markdownview"},
BareMetaCmdDecl{"csvview", "csvview"},
}
const (