1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 04:57:59 +00:00

Report stderr in shell (#37)

This commit is contained in:
Romein van Buren 2023-07-02 10:10:45 +02:00
parent 61142844fa
commit 7a5354c5f4
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
2 changed files with 20 additions and 10 deletions

View File

@ -77,11 +77,15 @@
</button> </button>
</BlankState> </BlankState>
{:else} {:else}
<pre>{result.output || ''}</pre> <pre>{result.output || ''}{#if result.stderr}<div class="error">{result.stderr}</div>{/if}</pre>
{/if} {/if}
</div> </div>
<div class="controls"> <div class="controls">
<button class="button" on:click={run}>
<Icon name="play" /> Run
</button>
{#key result} {#key result}
<div class="status flash-green"> <div class="status flash-green">
{#if result?.status} {#if result?.status}
@ -89,10 +93,6 @@
{/if} {/if}
</div> </div>
{/key} {/key}
<button class="btn" on:click={run}>
<Icon name="play" /> Run
</button>
</div> </div>
</div> </div>
@ -114,7 +114,7 @@
} }
.output { .output {
background-color: #111; background-color: #2e3027;
color: #fff; color: #fff;
overflow: auto; overflow: auto;
display: flex; display: flex;
@ -129,6 +129,10 @@
-webkit-user-select: text; -webkit-user-select: text;
cursor: text; cursor: text;
} }
.output pre .error {
color: #ff8989;
margin-top: 2px;
}
.output :global(.blankstate) { .output :global(.blankstate) {
margin: auto; margin: auto;
padding: 0.5rem; padding: 0.5rem;
@ -141,6 +145,6 @@
grid-column: 1 / 3; grid-column: 1 / 3;
} }
.controls .status { .controls .status {
margin-right: auto; margin-left: auto;
} }
</style> </style>

View File

@ -6,6 +6,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path" "path"
"strings"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/wailsapp/wails/v2/pkg/runtime" "github.com/wailsapp/wails/v2/pkg/runtime"
@ -13,6 +14,7 @@ import (
type ExecuteShellScriptResult struct { type ExecuteShellScriptResult struct {
Output string `json:"output"` Output string `json:"output"`
Stderr string `json:"stderr"`
Status int `json:"status"` Status int `json:"status"`
ErrorTitle string `json:"errorTitle"` ErrorTitle string `json:"errorTitle"`
ErrorDescription string `json:"errorDescription"` ErrorDescription string `json:"errorDescription"`
@ -85,14 +87,17 @@ func (a *App) ExecuteShellScript(hostKey, dbKey, collKey, script string) (result
return return
} }
var outbuf, errbuf strings.Builder
cmd := exec.Command("mongosh", "--file", fname, host.URI) cmd := exec.Command("mongosh", "--file", fname, host.URI)
stdout, err := cmd.Output() cmd.Stdout = &outbuf
cmd.Stderr = &errbuf
err = cmd.Run()
if exiterr, ok := err.(*exec.ExitError); ok { if exiterr, ok := err.(*exec.ExitError); ok {
result.Status = exiterr.ExitCode() result.Status = exiterr.ExitCode()
} else if err != nil { } else if err != nil {
runtime.LogWarningf(a.ctx, "Shell: failed to execute: mongosh --file %s: %s", fname, err.Error()) runtime.LogWarningf(a.ctx, "Shell: failed to execute: mongosh --file %s: %s", fname, err.Error())
result.ErrorTitle = "Could not execute script" result.ErrorTitle = "mongosh failure"
result.ErrorDescription = err.Error() result.ErrorDescription = err.Error()
return return
} else { } else {
@ -100,6 +105,7 @@ func (a *App) ExecuteShellScript(hostKey, dbKey, collKey, script string) (result
} }
os.Remove(fname) os.Remove(fname)
result.Output = string(stdout) result.Output = outbuf.String()
result.Stderr = errbuf.String()
return return
} }