0

How can I pass the arguments val and code to the group get

  • Code so far

import fire

class Get:

    def __init__(self, val="no", code=""):

        self.val = val
        self.code = code


    def get(self):
        return f"called get {self.val} {self.code}"

    def get_many(self):
        return f"called get many {self.val}"


class Pipeline:

    def __init__(self,):
        self.get = Get()

def main():
    fire.Fire(Pipeline)
  • The error I Got

$> my_p get --code="test" --val="yes" get

ERROR: Could not consume arg: --code=test
Usage: my_p get get <command>
basic mojo
  • 128
  • 2
  • 12

2 Answers2

0

according to https://github.com/google/python-fire/blob/master/docs/guide.md#version-4-firefireclass

you need to change :

self.get = Get

Besides, I recommend to not use the same name in "get" function in class Get. It is confusing.

duylamvo
  • 179
  • 5
0
import fire


class Get(object):
    def __init__(self, attr):
        self.attr = attr

    def get(self):
        return f"called get {self.attr.val} {self.attr.code}"

    def get_many(self):
        return f"called get many {self.attr.val}"


class Pipeline(object):
    def __init__(self, **kwargs):
        for key, val in kwargs.items():
            self.__dict__[key] = kwargs.get(key, val)
        self.get = Get(self)


if __name__ == "__main__":
    fire.Fire(Pipeline)

output

python my_p.py get --code="test" --val="yes" get
called get yes test
ovntatar
  • 416
  • 1
  • 3
  • 17