WIP dev thoughts for cw
#1
Replies: 1 comment 2 replies
-
Enabling CLI Users to Parameterize Function CallsBackgroundI have a function that accepts callable parameters: def func(get_data: Union[str, Callable], process_data: Union[str, Callable]):
data = get_data()
return process_data(data) This function is exposed as a CLI command using Currently, users can invoke it like: func --get-data key_to_a_data_get_function --process_data key_to_a_process_data_function The ChallengeI want to enable CLI users to not only specify functions by key, but also to parameterize them using Example scenario:
Desired Python equivalent: from functools import partial
func(
get_data=partial(multiple_has, n=2),
process_data=partial(prefix_it, prefix="-->")
) Desired CLI usage: func --get-data {"multiple_has": {"n": 2}} --process_data {"prefix_it": {"prefix": "-->"}} or: func --get-data (multiple_has -n 2) --process_data (prefix_it -prefix "-->") Questions
Implementation ConsiderationsIf no existing solution exists, I'm considering creating a decorator that preprocesses the arguments before passing them to Any insights on established patterns or best practices would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
To jot down thoughts and research about
cw
Beta Was this translation helpful? Give feedback.
All reactions