Skip to content

Commit 18a0a8f

Browse files
committed
enhancement of issue295
1 parent ed44d8b commit 18a0a8f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

fire/helptext.py

+39
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
import itertools
3737
import sys
38+
import inspect
39+
from types import FunctionType
3840

3941
from fire import completion
4042
from fire import custom_descriptions
@@ -68,6 +70,7 @@ def HelpText(component, trace=None, verbose=False):
6870
metadata = decorators.GetMetadata(component)
6971

7072
# Sections:
73+
spec.args=Checker(spec,component)
7174
name_section = _NameSection(component, info, trace=trace, verbose=verbose)
7275
synopsis_section = _SynopsisSection(
7376
component, actions_grouped_by_kind, spec, metadata, trace=trace)
@@ -95,6 +98,42 @@ def HelpText(component, trace=None, verbose=False):
9598
)
9699

97100

101+
def Checker(spec,component):
102+
"""
103+
desc:
104+
Checker funcition firstly checks type of component and afterthat
105+
it extract all parent classes.
106+
Return:
107+
case 1: If there is any parent class it will return all_args list.
108+
case 2: If there is no parent class so it will return only args list.
109+
"""
110+
if type(component) is not FunctionType and type(component) is not object:
111+
try:
112+
Inherit_classes_list=inspect.getmro(component)
113+
if len(Inherit_classes_list)>2:
114+
return ReturnAllArgs(Inherit_classes_list)
115+
except AttributeError as e:
116+
pass
117+
118+
return spec.args
119+
120+
121+
def ReturnAllArgs(Inherit_classes_list):
122+
"""
123+
Inherit_classes_list: It is a list which have collection of parent classes.
124+
Return: list of all arguments which is retrieved from parent classes.
125+
"""
126+
all_args = []
127+
if len(Inherit_classes_list)>2:
128+
for classes in Inherit_classes_list:
129+
argspec_tuple=inspect.getargspec(classes)
130+
args_list=argspec_tuple[0]
131+
for arg in args_list[1:]:
132+
all_args.append(arg)
133+
134+
return all_args
135+
136+
98137
def _NameSection(component, info, trace=None, verbose=False):
99138
"""The "Name" section of the help string."""
100139

0 commit comments

Comments
 (0)