Skip to content

Commit

Permalink
Options: Print help text when using erroneous parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Feb 22, 2025
1 parent f64c948 commit 4f1ff86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Added basic example program about how to import a dashboard
- Options: Permitted usage without authentication credentials or token
- Options: Do not assume defaults for `ACTION` and `--grafana_label` args
- Options: Print help text when using erroneous parameters

## 0.4.0 (2024-10-16)
- Fixed folder argument issue
Expand Down
10 changes: 7 additions & 3 deletions grafana_import/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def main():
# Get command line arguments.
parser = argparse.ArgumentParser(description="play with grafana dashboards json files.")

def print_help_and_exit():
parser.print_help(sys.stderr)
parser.exit(1)

parser.add_argument(
"-a",
"--allow_new",
Expand Down Expand Up @@ -235,8 +239,8 @@ def main():

try:
grafana_api = Grafana.Grafana(**params)
except Exception as e:
logger.error(f"ERROR: {e}")
except Exception as ex:
logger.error(str(ex))
sys.exit(1)

# Import
Expand Down Expand Up @@ -347,7 +351,7 @@ def process_dashboard(file_path):

else:
logger.error(f"Unknown action: {args.action}. Use one of: {parser._actions[-2].choices}")
sys.exit(1)
print_help_and_exit()


if __name__ == "__main__":
Expand Down

0 comments on commit 4f1ff86

Please sign in to comment.