You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by as...@apache.org on 2021/03/19 15:06:28 UTC
[airflow] 26/42: Add plain format output to cli tables (#14546)
This is an automated email from the ASF dual-hosted git repository.
ash pushed a commit to branch v2-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 051d239d95c78c97c9591a1a213aa0f0369db79d
Author: Tomek Urbaszek <tu...@gmail.com>
AuthorDate: Tue Mar 2 20:12:53 2021 +0100
Add plain format output to cli tables (#14546)
Add plain format output to cli tables so users can use standard
linux utilities like awk, xargs etc.
closes: #14517
(cherry picked from commit 0ef084c3b70089b9b061090f7d88ce86e3651ed4)
---
airflow/cli/cli_parser.py | 6 +++---
airflow/cli/simple_table.py | 11 +++++++++++
docs/apache-airflow/usage-cli.rst | 1 +
docs/spelling_wordlist.txt | 1 +
4 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/airflow/cli/cli_parser.py b/airflow/cli/cli_parser.py
index fae516e..e62346a 100644
--- a/airflow/cli/cli_parser.py
+++ b/airflow/cli/cli_parser.py
@@ -178,9 +178,9 @@ ARG_OUTPUT = Arg(
"-o",
"--output",
),
- help="Output format. Allowed values: json, yaml, table (default: table)",
- metavar="(table, json, yaml)",
- choices=("table", "json", "yaml"),
+ help="Output format. Allowed values: json, yaml, plain, table (default: table)",
+ metavar="(table, json, yaml, plain)",
+ choices=("table", "json", "yaml", "plain"),
default="table",
)
ARG_COLOR = Arg(
diff --git a/airflow/cli/simple_table.py b/airflow/cli/simple_table.py
index 696b9bf..3851272 100644
--- a/airflow/cli/simple_table.py
+++ b/airflow/cli/simple_table.py
@@ -23,6 +23,7 @@ from rich.box import ASCII_DOUBLE_HEAD
from rich.console import Console
from rich.syntax import Syntax
from rich.table import Table
+from tabulate import tabulate
from airflow.plugins_manager import PluginsDirectorySource
@@ -56,6 +57,15 @@ class AirflowConsole(Console):
table.add_row(*[str(d) for d in row.values()])
self.print(table)
+ def print_as_plain_table(self, data: List[Dict]):
+ """Renders list of dictionaries as a simple table than can be easily piped"""
+ if not data:
+ self.print("No data found")
+ return
+ rows = [d.values() for d in data]
+ output = tabulate(rows, tablefmt="plain", headers=data[0].keys())
+ print(output)
+
# pylint: disable=too-many-return-statements
def _normalize_data(self, value: Any, output: str) -> Optional[Union[list, str, dict]]:
if isinstance(value, (tuple, list)):
@@ -76,6 +86,7 @@ class AirflowConsole(Console):
"json": self.print_as_json,
"yaml": self.print_as_yaml,
"table": self.print_as_table,
+ "plain": self.print_as_plain_table,
}
renderer = output_to_renderer.get(output)
if not renderer:
diff --git a/docs/apache-airflow/usage-cli.rst b/docs/apache-airflow/usage-cli.rst
index 5dadab8..34f7ae7 100644
--- a/docs/apache-airflow/usage-cli.rst
+++ b/docs/apache-airflow/usage-cli.rst
@@ -182,6 +182,7 @@ Some Airflow commands like ``airflow dags list`` or ``airflow tasks states-for-d
which allow users to change the formatting of command's output. Possible options:
- ``table`` - renders the information as a plain text table
+ - ``simple`` - renders the information as simple table which can be parsed by standard linux utilities
- ``json`` - renders the information in form of json string
- ``yaml`` - render the information in form of valid yaml
diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt
index 84f1860..322ce7b 100644
--- a/docs/spelling_wordlist.txt
+++ b/docs/spelling_wordlist.txt
@@ -928,6 +928,7 @@ licence
licences
lifecycle
lineterminator
+linux
livy
localExecutor
localexecutor