From 43f95bfb5f2a88242729c91bee1669d1341b0169 Mon Sep 17 00:00:00 2001 From: Mohammad Ali RAHIMI KOUHBANANI Date: Fri, 14 Nov 2025 14:14:46 +0100 Subject: [PATCH] docs: Add section on handling missing arguments Addresses #633 by documenting best practices for handling missing arguments with default values and clear docstrings. This helps users create more user-friendly CLIs with better error messages. --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 1482d56d..c62d74e1 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,29 @@ python calculator.py double 10 # 20 python calculator.py double --number=15 # 30 ``` +### Handling Missing Arguments + +When required arguments are missing, Python Fire will raise an error. To improve user experience, consider providing default values and clear docstrings: + +```python +import fire + +def greet(name, greeting="Hello"): + """ + Greet someone with a custom message. + + Args: + name: The name of the person to greet (required) + greeting: The greeting message (default: Hello) + """ + return f"{greeting}, {name}!" + +if __name__ == '__main__': + fire.Fire(greet) +``` + +This provides helpful information when users run `--help` and makes missing argument errors clearer. + To learn how Fire behaves on functions, objects, dicts, lists, etc, and to learn about Fire's other features, see the [Using a Fire CLI page](docs/using-cli.md).