Skip to content

Add yaml/json output format support for many CLI commands #12699

Description

@turbaszek

Description

In list commands (for example dag runs, connection) we may output yaml/json representation of the information next to table representation. Why?

  • It's consistent and well structured
  • Easy to pipe to another command

We already have the --output flag which allows users to define "table style". We can use it to extend it functionality (personally I would be in favour of single predefined table)

Use case / motivation

Make airflow cli commands more consistent and easier to use.

Example:

root@1aa14208df15:/opt/airflow# airflow dags list-jobs
- dag_id: tasks_are_awesome
  end_date: '2020-11-29 11:04:39.652633+00:00'
  job_type: LocalTaskJob
  start_date: '2020-11-29 11:04:39.157918+00:00'
  state: success
- dag_id: tasks_are_awesome
  end_date: '2020-11-29 11:04:39.647816+00:00'
  job_type: LocalTaskJob
  start_date: '2020-11-29 11:04:39.129878+00:00'
  state: success
- dag_id: tasks_are_awesome
  end_date: '2020-11-29 11:04:39.682591+00:00'
  job_type: LocalTaskJob
  start_date: '2020-11-29 11:04:39.118681+00:00'
  state: success
- dag_id: tasks_are_awesome
  end_date: '2020-11-29 11:04:39.651830+00:00'
  job_type: LocalTaskJob
  start_date: '2020-11-29 11:04:39.105410+00:00'
  state: success
- dag_id: tasks_are_awesome
  end_date: '2020-11-29 11:04:29.604613+00:00'
  job_type: LocalTaskJob
  start_date: '2020-11-29 11:04:29.101670+00:00'
  state: success
- dag_id: tasks_are_awesome
  end_date: '2020-11-29 11:04:43.947281+00:00'
  job_type: BackfillJob
  start_date: '2020-11-29 11:04:23.702872+00:00'
  state: success

or json-like

root@1aa14208df15:/opt/airflow# airflow dags list-jobs
[{"dag_id": "tasks_are_awesome", "state": "success", "job_type": "LocalTaskJob", "start_date": "2020-11-29 11:04:39.157918+00:00", "end_date": "2020-11-29 11:04:39.652633+00:00"}, {"dag_id": "tasks_are_awesome", "state": "success", "job_type": "LocalTaskJob", "start_date": "2020-11-29 11:04:39.129878+00:00", "end_date": "2020-11-29 11:04:39.647816+00:00"}, {"dag_id": "tasks_are_awesome", "state": "success", "job_type": "LocalTaskJob", "start_date": "2020-11-29 11:04:39.118681+00:00", "end_date": "2020-11-29 11:04:39.682591+00:00"}, {"dag_id": "tasks_are_awesome", "state": "success", "job_type": "LocalTaskJob", "start_date": "2020-11-29 11:04:39.105410+00:00", "end_date": "2020-11-29 11:04:39.651830+00:00"}, {"dag_id": "tasks_are_awesome", "state": "success", "job_type": "LocalTaskJob", "start_date": "2020-11-29 11:04:29.101670+00:00", "end_date": "2020-11-29 11:04:29.604613+00:00"}, {"dag_id": "tasks_are_awesome", "state": "success", "job_type": "BackfillJob", "start_date": "2020-11-29 11:04:23.702872+00:00", "end_date": "2020-11-29 11:04:43.947281+00:00"}]

Related Issues

#12698 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions