From 709920ad8effb1955533860fec7a081c1d778847 Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 23 Aug 2022 13:14:14 -0700 Subject: [PATCH] add ephemeral to line --- db/migrations/000001_init.up.sql | 1 + pkg/cmdrunner/cmdrunner.go | 4 ++++ pkg/sstore/dbops.go | 4 ++-- pkg/sstore/sstore.go | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/db/migrations/000001_init.up.sql b/db/migrations/000001_init.up.sql index 1c6d6bf6..b428e2cb 100644 --- a/db/migrations/000001_init.up.sql +++ b/db/migrations/000001_init.up.sql @@ -66,6 +66,7 @@ CREATE TABLE line ( linetype varchar(10) NOT NULL, text text NOT NULL, cmdid varchar(36) NOT NULL, + ephemeral boolean NOT NULL, PRIMARY KEY (sessionid, windowid, lineid) ); diff --git a/pkg/cmdrunner/cmdrunner.go b/pkg/cmdrunner/cmdrunner.go index b8bef908..3ee5e1f3 100644 --- a/pkg/cmdrunner/cmdrunner.go +++ b/pkg/cmdrunner/cmdrunner.go @@ -386,6 +386,10 @@ func evalCommandInternal(ctx context.Context, pk *scpacket.FeCommandPacketType) MetaSubCmd: metaSubCmd, Kwargs: pk.Kwargs, } + if strings.HasSuffix(commandStr, " ?") { + newPk.Kwargs["ephemeral"] = "1" + commandStr = commandStr[0 : len(commandStr)-2] + } if metaCmd == "run" || metaCmd == "comment" { newPk.Args = []string{commandStr} } else if (metaCmd == "setenv" || metaCmd == "unset") && metaSubCmd == "" { diff --git a/pkg/sstore/dbops.go b/pkg/sstore/dbops.go index d8a3c0ac..a0de382d 100644 --- a/pkg/sstore/dbops.go +++ b/pkg/sstore/dbops.go @@ -398,8 +398,8 @@ func InsertLine(ctx context.Context, line *LineType, cmd *CmdType) error { if !hasWindow { return fmt.Errorf("window not found, cannot insert line[%s/%s]", line.SessionId, line.WindowId) } - query = `INSERT INTO line ( sessionid, windowid, lineid, ts, userid, linetype, text, cmdid) - VALUES (:sessionid,:windowid,:lineid,:ts,:userid,:linetype,:text,:cmdid)` + query = `INSERT INTO line ( sessionid, windowid, lineid, ts, userid, linetype, text, cmdid, ephemeral) + VALUES (:sessionid,:windowid,:lineid,:ts,:userid,:linetype,:text,:cmdid,:ephemeral)` tx.NamedExecWrap(query, line) if cmd != nil { cmdMap := cmd.ToMap() diff --git a/pkg/sstore/sstore.go b/pkg/sstore/sstore.go index 32d49180..f82d38d2 100644 --- a/pkg/sstore/sstore.go +++ b/pkg/sstore/sstore.go @@ -278,6 +278,7 @@ type LineType struct { LineType string `json:"linetype"` Text string `json:"text,omitempty"` CmdId string `json:"cmdid,omitempty"` + Ephemeral bool `json:"ephemeral,omitempty"` Remove bool `json:"remove,omitempty"` }