Skip to content
Merged
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
35 changes: 35 additions & 0 deletions cortex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3056,6 +3056,33 @@ def main():
help="Enable verbose output",
)

# Stdin Piping Support
stdin_parser = subparsers.add_parser("stdin", help="Process piped stdin data")
stdin_parser.add_argument(
"action",
nargs="?",
default="info",
choices=["info", "analyze", "passthrough", "stats"],
help="Action to perform (default: info)",
)
stdin_parser.add_argument(
"--max-lines",
type=int,
default=1000,
help="Maximum lines to process (default: 1000)",
)
stdin_parser.add_argument(
"--truncation",
choices=["head", "tail", "middle", "sample"],
default="middle",
help="Truncation mode for large input (default: middle)",
)
stdin_parser.add_argument(
"-v", "--verbose",
action="store_true",
help="Enable verbose output",
)

args = parser.parse_args()

# The Guard: Check for empty commands before starting the CLI
Expand Down Expand Up @@ -3148,6 +3175,14 @@ def main():
action=getattr(args, "action", "status"),
verbose=getattr(args, "verbose", False),
)
elif args.command == "stdin":
from cortex.stdin_handler import run_stdin_handler
return run_stdin_handler(
action=getattr(args, "action", "info"),
max_lines=getattr(args, "max_lines", 1000),
truncation=getattr(args, "truncation", "middle"),
verbose=getattr(args, "verbose", False),
Comment on lines +3181 to +3184
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of getattr with default values here is redundant. The stdin subparser defines default values for action, max_lines, truncation, and verbose. When args.command == "stdin", these attributes are guaranteed to be present on the args object. Direct access would be cleaner and more readable.

Suggested change
action=getattr(args, "action", "info"),
max_lines=getattr(args, "max_lines", 1000),
truncation=getattr(args, "truncation", "middle"),
verbose=getattr(args, "verbose", False),
action=args.action,
max_lines=args.max_lines,
truncation=args.truncation,
verbose=args.verbose,

)
else:
parser.print_help()
return 1
Expand Down
Loading
Loading