pydoit / doit

CLI task management & automation tool
http://pydoit.org
MIT License
1.84k stars 175 forks source link

create required CmdOption #458

Closed timhemel closed 1 year ago

timhemel commented 1 year ago

doit does not check if command options (i.e. cmdline arguments to a task) are present before creating the task. This results in an error later on.

doit could check this if it would look for a required flag in the task dict params section.

Example:

            'params': [{
                    'name': 'settings',
                    'short': 's',
                    'long': 'settings',
                    'type': str,
                    'default': None,
                    'required': True,  # this indicates the field is required
                    'help': 'path to program settings'
                }],

It is not a perfect command line option validation as you would have in argparse or click, but it saves some headaches when using doit.

Describe alternatives you've considered

I could not think of any elegant alternatives.

Funding

Fund with Polar

timhemel commented 1 year ago

I realized that this may introduce problems if required flags are used with the decorator task_params, because then certain parameters not relevant to the current task may be required. task_params also provides a way to validate the command line parameters. so this solves my problem.