Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion snuba/admin/static/sql_shell/command_parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParsedCommand, ShellMode } from "./types";
import { ParsedCommand, ShellMode, OutputFormat } from "./types";

/**
* Command definition for the shell parser.
Expand Down Expand Up @@ -90,6 +90,15 @@ const COMMANDS: CommandDefinition[] = [
modes: ["system"],
},

// FORMAT TABLE|JSON|CSV|VERTICAL - Set output format
{
pattern: /^FORMAT\s+(TABLE|JSON|CSV|VERTICAL)$/i,
parse: (match) => ({
type: "format",
format: match[1].toLowerCase() as OutputFormat,
}),
},

// HELP - Show help message
{
pattern: /^HELP$/i,
Expand Down
19 changes: 19 additions & 0 deletions snuba/admin/static/sql_shell/shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ function SQLShell({ api, mode }: SQLShellProps) {
});
break;

case "format":
setState((prev) => ({
...prev,
outputFormat: parsed.format,
}));
addHistoryEntry({
type: "info",
content: `Output format set to: ${parsed.format.toUpperCase()}`,
timestamp: Date.now(),
});
break;

case "sql":
if (!state.currentStorage) {
addHistoryEntry({
Expand Down Expand Up @@ -451,6 +463,7 @@ function SQLShell({ api, mode }: SQLShellProps) {
entries={state.history}
traceFormatted={state.traceFormatted}
mode={mode}
outputFormat={state.outputFormat}
isExecuting={state.isExecuting}
/>
{suggestions.length > 0 && (
Expand Down Expand Up @@ -550,6 +563,12 @@ function SQLShell({ api, mode }: SQLShellProps) {
</div>
</>
)}
<div className={classes.statusItem}>
<span>FORMAT:</span>
<span className={classes.statusActive}>
{state.outputFormat.toUpperCase()}
</span>
</div>
<div style={{ color: "#6e7681" }}>Tab: Autocomplete | Enter: Execute | Shift+Enter: New line | ↑↓: History</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions snuba/admin/static/sql_shell/shell_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function createInitialState(mode: ShellMode): ShellState {
profileEnabled: true,
traceFormatted: true,
sudoEnabled: false,
outputFormat: "table",
history: [],
commandHistory: loadCommandHistory(mode),
historyIndex: -1,
Expand Down
Loading
Loading