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

Provide a help string when registering commands #154

Merged
merged 2 commits into from
May 6, 2016
Merged

Conversation

kastiglione
Copy link
Contributor

@kastiglione kastiglione commented May 6, 2016

I don't know when it was first added, but command script add has a --help flag, which defines the help text to show in the output of the help command.

This change calls the description method on each command, extracts the first line, and then passes that as the help string when registering the command.

Example output:

pa11y        -- Print accessibility labels of all views in hierarchy of <aView>
pa11yi       -- Print accessibility identifiers of all views in hierarchy of <aView>
pactions     -- Print the actions and targets of a control.
paltrace     -- Print the Auto Layout trace for the given view. Defaults to the key window.
panim        -- Prints if the code is currently execution with a UIView animation block.
pbcopy       -- Print object and copy output to clipboard

I don't know when it was added, but `command script add` has a --help
flag, which defines the help text to show in the output of the `help`
command.

This change calls the description method on each command, extracts the
first line, and then passes that as the help string when registering the
command.
@ghost ghost added the CLA Signed label May 6, 2016
@@ -41,6 +41,7 @@ def loadCommandsInDirectory(commandsDirectory):
def loadCommand(module, command, directory, filename, extension):
func = makeRunCommand(command, os.path.join(directory, filename + extension))
name = command.name()
helpText = command.description().split('\n', 1)[0] # first line of description

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use str.splitlines() here instead, unless the maxsplit=1 here is important to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's definitely more readable. The use of maxsplit was to avoid doing more work than necessary.

@modocache
Copy link

LGTM!

@kastiglione kastiglione merged commit de22648 into master May 6, 2016
@kastiglione kastiglione deleted the command-help branch May 6, 2016 22:56
@kastiglione
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants