google / google/python-fire

Improve error message when required argument is missing

未关闭
#633 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
28.2k
派生
1.5k
PR 合并指标
30 天内没有已合并 PR

描述

## Description
When a required function argument is not provided via the command line, Python Fire raises a generic TypeError that doesn't clearly indicate which argument is missing or how to provide it.

## Current Behavior
```bash
$ python my_script.py greet
TypeError: greet() missing 1 required positional argument: 'name'
```

## Expected Behavior
A more user-friendly error message that would guide the user:
```
$ python my_script.py greet
Error: Missing required argument 'name'
Usage: my_script.py greet
```

## Motivation
This would significantly improve the user experience, especially for new users who are unfamiliar with Python tracebacks. Clear error messages are crucial for CLI tools.

## Environment
- Python Fire version: 0.7.1
- Python version: 3.11
- OS: macOS

## Possible Solution
Catch TypeError exceptions in the argument parsing logic and check if they're related to missing arguments, then provide a more descriptive message with usage hints.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。