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:
parent
61142844fa
commit
7a5354c5f4
@ -77,11 +77,15 @@
|
||||
</button>
|
||||
</BlankState>
|
||||
{:else}
|
||||
<pre>{result.output || ''}</pre>
|
||||
<pre>{result.output || ''}{#if result.stderr}<div class="error">{result.stderr}</div>{/if}</pre>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<button class="button" on:click={run}>
|
||||
<Icon name="play" /> Run
|
||||
</button>
|
||||
|
||||
{#key result}
|
||||
<div class="status flash-green">
|
||||
{#if result?.status}
|
||||
@ -89,10 +93,6 @@
|
||||
{/if}
|
||||
</div>
|
||||
{/key}
|
||||
|
||||
<button class="btn" on:click={run}>
|
||||
<Icon name="play" /> Run
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -114,7 +114,7 @@
|
||||
}
|
||||
|
||||
.output {
|
||||
background-color: #111;
|
||||
background-color: #2e3027;
|
||||
color: #fff;
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
@ -129,6 +129,10 @@
|
||||
-webkit-user-select: text;
|
||||
cursor: text;
|
||||
}
|
||||
.output pre .error {
|
||||
color: #ff8989;
|
||||
margin-top: 2px;
|
||||
}
|
||||
.output :global(.blankstate) {
|
||||
margin: auto;
|
||||
padding: 0.5rem;
|
||||
@ -141,6 +145,6 @@
|
||||
grid-column: 1 / 3;
|
||||
}
|
||||
.controls .status {
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
}
|
||||
</style>
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
@ -13,6 +14,7 @@ import (
|
||||
|
||||
type ExecuteShellScriptResult struct {
|
||||
Output string `json:"output"`
|
||||
Stderr string `json:"stderr"`
|
||||
Status int `json:"status"`
|
||||
ErrorTitle string `json:"errorTitle"`
|
||||
ErrorDescription string `json:"errorDescription"`
|
||||
@ -85,14 +87,17 @@ func (a *App) ExecuteShellScript(hostKey, dbKey, collKey, script string) (result
|
||||
return
|
||||
}
|
||||
|
||||
var outbuf, errbuf strings.Builder
|
||||
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 {
|
||||
result.Status = exiterr.ExitCode()
|
||||
} else if err != nil {
|
||||
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()
|
||||
return
|
||||
} else {
|
||||
@ -100,6 +105,7 @@ func (a *App) ExecuteShellScript(hostKey, dbKey, collKey, script string) (result
|
||||
}
|
||||
|
||||
os.Remove(fname)
|
||||
result.Output = string(stdout)
|
||||
result.Output = outbuf.String()
|
||||
result.Stderr = errbuf.String()
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user