Skip to content
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

Simple implementation of allowing externally defined formatters #75

Closed
wants to merge 7 commits into from
Prev Previous commit
Next Next commit
updating so that package name is used for Usage display when file bei…
…ng run is '__main__.py'

(uses filepath of __main__.py to determine the package name)
monkut committed Jul 5, 2017

Verified

This commit was signed with the committer’s verified signature.
henrikvtcodes Henrik VT
commit ea3c57d131b1dc408daed6d68b97296614309dca
9 changes: 9 additions & 0 deletions fire/helputils.py
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
from __future__ import print_function

import inspect
import os

from fire import completion
from fire import inspectutils
@@ -113,12 +114,20 @@ def HelpString(component, trace=None, verbose=False):
format_string = '{{field:{max_size}s}} {{value}}'.format(max_size=max_size)

lines = []
source_filepath = None
for field in fields:
value = _DisplayValue(info, field, padding=max_size + 1)
if field == 'file':
source_filepath = value # assumes that 'file' comes before usage (See 'fields' above)
if value:
if lines and field == 'usage':
lines.append('') # Ensure a blank line before usage.

# use package_name if file called is __main__.py
if source_filepath and source_filepath.endswith('__main__.py'):
package_path, _ = os.path.split(source_filepath)
_, package_name = os.path.split(package_path)
value = value.replace('__main__.py', package_name)
lines.append(format_string.format(
field=_NormalizeField(field) + ':',
value=value,