[3/4] dts: show help when DTS is ran without args

Message ID 20240122182611.1904974-4-luca.vizzarro@arm.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series dts: error and usage improvements |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Luca Vizzarro Jan. 22, 2024, 6:26 p.m. UTC
  This commit changes the default behaviour of DTS, making it so that the
user automatically sees the help and usage page when running it without
any arguments set. Instead of being welcomed by an error message.

Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>
Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
---
 dts/framework/settings.py | 6 ++++++
 1 file changed, 6 insertions(+)
  

Patch

diff --git a/dts/framework/settings.py b/dts/framework/settings.py
index acfe5cad44..5809fd4e91 100644
--- a/dts/framework/settings.py
+++ b/dts/framework/settings.py
@@ -71,6 +71,7 @@ 
 
 import argparse
 import os
+import sys
 from collections.abc import Callable, Iterable, Sequence
 from dataclasses import dataclass, field
 from pathlib import Path
@@ -315,6 +316,11 @@  def get_settings() -> Settings:
 
     The inputs are taken from the command line and from environment variables.
     """
+
+    if len(sys.argv) == 1:
+        _get_parser().print_help()
+        sys.exit(1)
+
     parsed_args = _get_parser().parse_args()
     return Settings(
         config_file_path=parsed_args.config_file,