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

Fix #862 - Sorts Help Commands by Script #917

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/robot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Robot
@alias = false
@adapter = null
@Response = Response
@commands = []
@commands = {}
@listeners = []
@logger = new Log process.env.HUBOT_LOG_LEVEL or 'info'
@pingIntervalId = null
Expand Down Expand Up @@ -343,7 +343,10 @@ class Robot
#
# Returns an Array of help commands for running scripts.
helpCommands: ->
@commands.sort()
output = []
for script, cmds of @commands
output = output.concat(cmds.sort())
return output

# Private: load help info from a loaded script.
#
Expand All @@ -354,7 +357,7 @@ class Robot
@logger.debug "Parsing help for #{path}"
scriptName = Path.basename(path).replace /\.(coffee|js)$/, ''
scriptDocumentation = {}

@commands[scriptName] = []
body = Fs.readFileSync path, 'utf-8'

currentSection = null
Expand All @@ -374,7 +377,7 @@ class Robot
if currentSection
scriptDocumentation[currentSection].push cleanedLine.trim()
if currentSection is 'commands'
@commands.push cleanedLine.trim()
@commands[scriptName].push cleanedLine.trim()

if currentSection is null
@logger.info "#{path} is using deprecated documentation syntax"
Expand All @@ -384,7 +387,7 @@ class Robot
continue if not line.match('-')
cleanedLine = line[2..line.length].replace(/^hubot/i, @name).trim()
scriptDocumentation.commands.push cleanedLine
@commands.push cleanedLine
@commands[scriptName].push cleanedLine

# Public: A helper send function which delegates to the adapter's send
# function.
Expand Down