diff options
author | Cedric Brandily <zzelle@gmail.com> | 2015-02-21 00:11:14 +0100 |
---|---|---|
committer | Cedric Brandily <zzelle@gmail.com> | 2015-02-21 00:15:11 +0100 |
commit | 08ed6b4c99ef7d7e972b82682ad3db43ee3fbaea (patch) | |
tree | 4532b67e787e6689475339dd4da30a89ebe3e1f0 | |
parent | 01c8d8f05cb404d9f06745f24c431f83edec54bf (diff) | |
download | cliff-08ed6b4c99ef7d7e972b82682ad3db43ee3fbaea.tar.gz |
Hide prompt in batch/pipe mode
Currently cliff prints prompt in batch/pipe mode:
I-AM-A-PROMPT$ echo file | cliffdemo
(cliffdemo) +---------------+--------------+
| Field | Value |
+---------------+--------------+
| Name | . |
| Size | 4096 |
| UID | 1124 |
| GID | 1000 |
| Modified Time | 1424473806.9 |
+---------------+--------------+
(cliffdemo) I-AM-A-PROMPT$
This change removes the prompt when batch/pipe mode is detected:
I-AM-A-PROMPT$ echo file | cliffdemo
+---------------+--------------+
| Field | Value |
+---------------+--------------+
| Name | . |
| Size | 4096 |
| UID | 1124 |
| GID | 1000 |
| Modified Time | 1424473806.9 |
+---------------+--------------+
I-AM-A-PROMPT$
Change-Id: Id17b3a3a4e63f24a0f5db92fb9fe71180ce752e2
Closes-Bug: #1381680
-rw-r--r-- | cliff/interactive.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/cliff/interactive.py b/cliff/interactive.py index e5cddb0..c99a6c6 100644 --- a/cliff/interactive.py +++ b/cliff/interactive.py @@ -5,6 +5,7 @@ import itertools import logging import logging.handlers import shlex +import sys import cmd2 @@ -34,7 +35,11 @@ class InteractiveApp(cmd2.Cmd): def __init__(self, parent_app, command_manager, stdin, stdout): self.parent_app = parent_app - self.prompt = '(%s) ' % parent_app.NAME + if not hasattr(sys.stdin, 'isatty') or sys.stdin.isatty(): + self.prompt = '(%s) ' % parent_app.NAME + else: + # batch/pipe mode + self.prompt = '' self.command_manager = command_manager cmd2.Cmd.__init__(self, 'tab', stdin=stdin, stdout=stdout) |