From 429c41cfd0198b02124fc96d35f485027e4b6b0d Mon Sep 17 00:00:00 2001 From: sawka Date: Mon, 22 Aug 2022 18:53:38 -0700 Subject: [PATCH] show environment --- pkg/cmdrunner/cmdrunner.go | 15 +++++++++++++++ pkg/sstore/updatebus.go | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/cmdrunner/cmdrunner.go b/pkg/cmdrunner/cmdrunner.go index 8ade405ed..b8bef9085 100644 --- a/pkg/cmdrunner/cmdrunner.go +++ b/pkg/cmdrunner/cmdrunner.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/alessio/shellescape" "github.com/google/uuid" "github.com/scripthaus-dev/mshell/pkg/base" "github.com/scripthaus-dev/mshell/pkg/packet" @@ -524,6 +525,20 @@ func SetEnvCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstor return nil, fmt.Errorf("remote state is not available") } envMap := shexec.ParseEnv0(ids.RemoteState.Env0) + if len(pk.Args) == 0 { + var infoLines []string + for varName, varVal := range envMap { + line := fmt.Sprintf("%s=%s", varName, shellescape.Quote(varVal)) + infoLines = append(infoLines, line) + } + update := sstore.InfoUpdate{ + Info: &sstore.InfoMsgType{ + InfoTitle: fmt.Sprintf("[%s] environment", ids.RemoteName), + InfoLines: infoLines, + }, + } + return update, nil + } setVars := make(map[string]bool) for _, argStr := range pk.Args { eqIdx := strings.Index(argStr, "=") diff --git a/pkg/sstore/updatebus.go b/pkg/sstore/updatebus.go index 3ec9708c8..155c491cf 100644 --- a/pkg/sstore/updatebus.go +++ b/pkg/sstore/updatebus.go @@ -84,8 +84,9 @@ type InfoMsgType struct { InfoTitle string `json:"infotitle"` InfoError string `json:"infoerror,omitempty"` InfoMsg string `json:"infomsg,omitempty"` - InfoComps []string `json:"infocomps"` - InfoCompsMore bool `json:"infocompssmore"` + InfoComps []string `json:"infocomps,omitempty"` + InfoCompsMore bool `json:"infocompssmore,omitempty"` + InfoLines []string `json:"infolines,omitempty"` TimeoutMs int64 `json:"timeoutms,omitempty"` }