eonu / feud

Build powerful CLIs with simple idiomatic Python, driven by type hints. Not all arguments are bad.
https://feud.readthedocs.io
MIT License
57 stars 2 forks source link

Support arbitrary instances of objects #154

Open eonu opened 1 month ago

eonu commented 1 month ago

Does this suggestion already exist?

Feature description

Bit of a wild proposition, and would probably be a big project, but basic example:

import feud

class Number:
    def __init__(self, value: int, /) -> None:
        self.value = value

    def add(self, summand: int) -> int:
        return self.value + summand

if __name__ == "__main__":
    number = Number(10)
    feud.run(number, ["add", "5"], standalone_mode=False)  # => 15
    feud.run(number.add, ["5"], standalone_mode=False)  # => 15

Should ideally support instance methods, class methods, static methods, properties/setters.

Probably needs to store the object in ctx and generate commands based on the object's members, which are forwarded to the corresponding method.

Help could maybe display class docstring plus set attribute values (e.g. self.value = 10) in the example above.