legacy_commands.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. from __future__ import annotations
  18. from argparse import ArgumentError
  19. COMMAND_MAP = {
  20. "worker": "celery worker",
  21. "flower": "celery flower",
  22. "trigger_dag": "dags trigger",
  23. "delete_dag": "dags delete",
  24. "show_dag": "dags show",
  25. "list_dag": "dags list",
  26. "dag_status": "dags status",
  27. "backfill": "dags backfill",
  28. "list_dag_runs": "dags list-runs",
  29. "pause": "dags pause",
  30. "unpause": "dags unpause",
  31. "test": "tasks test",
  32. "clear": "tasks clear",
  33. "list_tasks": "tasks list",
  34. "task_failed_deps": "tasks failed-deps",
  35. "task_state": "tasks state",
  36. "run": "tasks run",
  37. "render": "tasks render",
  38. "initdb": "db init",
  39. "resetdb": "db reset",
  40. "upgradedb": "db upgrade",
  41. "checkdb": "db check",
  42. "shell": "db shell",
  43. "pool": "pools",
  44. "list_users": "users list",
  45. "create_user": "users create",
  46. "delete_user": "users delete",
  47. }
  48. def check_legacy_command(action, value):
  49. """Check command value and raise error if value is in removed command."""
  50. new_command = COMMAND_MAP.get(value)
  51. if new_command is not None:
  52. msg = f"`airflow {value}` command, has been removed, please use `airflow {new_command}`"
  53. raise ArgumentError(action, msg)