-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
display commands in a particular order #298
Comments
@wiso can you please share some more information about how the current help result shows up and how would you like to customize it with an example or sample screenshots ? |
sure, actually is is very simple. This is the help I get
the commands are displayed in alphabetical order. I would like to customize that order. |
Hello @wiso import fire def hello(name="World"): if name == 'main': when I run the code with the following command : python firecli.py vinayak --help , it shows the list of commands that could be used in alphabetical order (screenshot attached). However, I do not see two different options where it displays the commands and values. How would you like the command display options to be customized ? Can you please elaborate on this part ? |
There is no issue of any kind. My point is just that I would like to show then list of actions in an order defined by me, and not by alphabetical order. |
Ok got it. I understood your point. |
Option 1: When reordering sequence is specified using command line.File-name = fire_test.py import fire
class CustomSequence(object):
def __init__(self, offset=1):
self.offset = offset
def generate(self, start, stop):
return ' '.join(str(item) for item in range(start, stop, self.offset))
def generate2(self):
print("Function 1")
def generated(self):
print("Function 2")
def cool(self):
return "Function 3"
def cool_for(self):
print("Function 4")
def rush_hour(self):
print("Function 5")
if __name__ == '__main__':
fire.Fire(CustomSequence()) Command line input with default sequence: python fire_test.py --help Output:
Command line input when a user specifies a sequence: python fire_test.py --help rush_hour generate2 Output:
Option 2: When reordering sequence is specified in the file (fire_test.py in this case)import fire
class CustomSequence(object):
def __init__(self, offset=1):
self.offset = offset
def generate(self, start, stop):
return ' '.join(str(item) for item in range(start, stop, self.offset))
def generate2(self):
print("Function 1")
def generated(self):
print("Function 2")
def cool(self):
return "Function 3"
def cool_for(self):
print("Function 4")
def rush_hour(self):
print("Function 5")
if __name__ == '__main__':
""" New paramter for the sequence has been added over here, which gets passed
on through multiple calls to _MakeUsageDetailsSection function in helptext.py """
fire.Fire(CustomSequence(), help_sequence = ["rush_hour","generate2"]) Output:
Please let me know either option 1 or 2 resolves the issue or is something else expected ? |
Thank you. I haven't tested, but the last solution seems to do what I want in the simplest way. |
Please validate the changes and test it using the code in my forked repository branch. Since the code mentioned in above comments does not contain all the changes required in core.py and helptext.py files. |
your example works only if I run |
My initial understanding was that the reordering was required in only |
ok, thanks. There is a problem, I have added a documentation string in one function and the order is not correct
|
Thanks for pointing out the error. I have made changes to the code so that now documentation strings don't affect the reordering of the commands. I have also made changes so that every occurrence where commands get displayed as help will have this reordering. |
Thank, it works! |
Thanks for the confirmation. I will soon raise a pull request with the change. |
In the help Fire displays commands in alphabetical order. It would be nice to be able to show them in a custom order specified by the user.
The text was updated successfully, but these errors were encountered: