summaryrefslogtreecommitdiff
path: root/internal/server/handlers/readcommand.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-20 13:51:06 +0300
committerPaul Buetow <paul@buetow.org>2025-06-20 13:51:06 +0300
commit4a8f1690c3e2e6aec34f22b516f0598c6a0da070 (patch)
tree82ecb4568df3e91c7958c2e9f491546e6f7e9701 /internal/server/handlers/readcommand.go
parentb0a1e7928d5147d2a9fe0df710bf7c75a777e0d0 (diff)
Fix dcat/dgrep serverless mode to show REMOTE protocol formatrefactor-trail-1
- Add serverless flag to CatProcessor and GrepProcessor - Format output with REMOTE|hostname|transmittedPerc|count|sourceID|content in serverless mode - Use actual system hostname instead of "serverless" placeholder - Preserve plain mode behavior (no formatting when --plain is used) - Fix grep processor to properly separate multiple matched lines - Add shared getHostname utility function - Update tests to include serverless parameter This fixes the regression where dcat and dgrep in serverless mode were not showing the dtail protocol format with transmission info and status details. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/server/handlers/readcommand.go')
-rw-r--r--internal/server/handlers/readcommand.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/internal/server/handlers/readcommand.go b/internal/server/handlers/readcommand.go
index 0a99aaa..901c929 100644
--- a/internal/server/handlers/readcommand.go
+++ b/internal/server/handlers/readcommand.go
@@ -147,6 +147,7 @@ func (r *readCommand) readFiles(ctx context.Context, ltx lcontext.LContext,
var output io.Writer
if r.server.serverless {
// In serverless mode, write to stdout with color support
+ // Note: plain mode means no colors, so noColor = plain
output = NewColorWriter(os.Stdout, r.server.plain)
} else {
// In client-server mode, write to server handler lines channel
@@ -209,6 +210,11 @@ func (r *readCommand) readFiles(ctx context.Context, ltx lcontext.LContext,
}
}
}
+
+ // Close the output writer if it's a ColorWriter
+ if colorWriter, ok := output.(*ColorWriter); ok {
+ colorWriter.Close()
+ }
}
// readStdin processes stdin using direct processing
@@ -217,6 +223,7 @@ func (r *readCommand) readStdin(ctx context.Context, ltx lcontext.LContext, re r
var output io.Writer
if r.server.serverless {
// In serverless mode, write to stdout with color support
+ // Note: plain mode means no colors, so noColor = plain
output = NewColorWriter(os.Stdout, r.server.plain)
} else {
// In client-server mode, write to server handler lines channel
@@ -236,6 +243,11 @@ func (r *readCommand) readStdin(ctx context.Context, ltx lcontext.LContext, re r
r.server.sendln(r.server.serverMessages, dlog.Server.Error(r.server.user,
"Error processing stdin", err))
}
+
+ // Close the output writer if it's a ColorWriter
+ if colorWriter, ok := output.(*ColorWriter); ok {
+ colorWriter.Close()
+ }
}
// isMapReduceCommand checks if this is a command that's part of a MapReduce operation
@@ -293,22 +305,22 @@ func (r *readCommand) createProcessor(re regex.Regex, ltx lcontext.LContext, out
mapProcessor, err := fs.NewMapProcessor(plain, hostname, queryStr, output)
if err != nil {
dlog.Server.Error(r.server.user, "Failed to create MapReduce processor", err)
- return fs.NewGrepProcessor(re, plain, noColor, hostname, ltx.BeforeContext, ltx.AfterContext, ltx.MaxCount), false
+ return fs.NewGrepProcessor(re, plain, noColor, hostname, r.server.serverless, ltx.BeforeContext, ltx.AfterContext, ltx.MaxCount), false
}
return mapProcessor, false
}
- return fs.NewGrepProcessor(re, plain, noColor, hostname, ltx.BeforeContext, ltx.AfterContext, ltx.MaxCount), false
+ return fs.NewGrepProcessor(re, plain, noColor, hostname, r.server.serverless, ltx.BeforeContext, ltx.AfterContext, ltx.MaxCount), false
case omode.CatClient:
if isMapReduce && queryStr != "" {
// This is a standalone MapReduce cat operation
mapProcessor, err := fs.NewMapProcessor(plain, hostname, queryStr, output)
if err != nil {
dlog.Server.Error(r.server.user, "Failed to create MapReduce processor", err)
- return fs.NewCatProcessor(plain, noColor, hostname), false
+ return fs.NewCatProcessor(plain, noColor, hostname, r.server.serverless), false
}
return mapProcessor, false
}
- return fs.NewCatProcessor(plain, noColor, hostname), false
+ return fs.NewCatProcessor(plain, noColor, hostname, r.server.serverless), false
case omode.TailClient:
if isMapReduce && queryStr != "" {
// This is a standalone MapReduce tail operation
@@ -327,14 +339,14 @@ func (r *readCommand) createProcessor(re regex.Regex, ltx lcontext.LContext, out
mapProcessor, err := fs.NewMapProcessor(plain, hostname, queryStr, output)
if err != nil {
dlog.Server.Error(r.server.user, "Failed to create MapReduce processor", err)
- return fs.NewGrepProcessor(re, plain, noColor, hostname, ltx.BeforeContext, ltx.AfterContext, ltx.MaxCount), false
+ return fs.NewGrepProcessor(re, plain, noColor, hostname, r.server.serverless, ltx.BeforeContext, ltx.AfterContext, ltx.MaxCount), false
}
return mapProcessor, false
}
// Fallback
- return fs.NewGrepProcessor(re, plain, noColor, hostname, ltx.BeforeContext, ltx.AfterContext, ltx.MaxCount), false
+ return fs.NewGrepProcessor(re, plain, noColor, hostname, r.server.serverless, ltx.BeforeContext, ltx.AfterContext, ltx.MaxCount), false
default:
// Default to grep behavior
- return fs.NewGrepProcessor(re, plain, noColor, hostname, ltx.BeforeContext, ltx.AfterContext, ltx.MaxCount), false
+ return fs.NewGrepProcessor(re, plain, noColor, hostname, r.server.serverless, ltx.BeforeContext, ltx.AfterContext, ltx.MaxCount), false
}
}