Skip to content

Commit

Permalink
Add switch for disabling the http server
Browse files Browse the repository at this point in the history
  • Loading branch information
tombell committed Dec 24, 2011
1 parent 959b26d commit 5fd81c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 11 additions & 1 deletion bin/hubot
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Switches = [
[ "-s", "--enable-slash", "Enable replacing the robot's name with '/' (deprecated)" ],
[ "-l", "--alias ALIAS", "Enable replacing the robot's name with alias" ],
[ "-n", "--name NAME", "The name of the robot in chat" ],
[ "-d", "--disable-httpd", "Disable the HTTP server" ],
[ "-v", "--version", "Displays the version of hubot installed" ]
]

Expand All @@ -28,6 +29,7 @@ Options =
create: false
adapter: "shell"
alias: false
enableHttpd: true

Parser = new OptParse.OptionParser(Switches)
Parser.banner = "Usage hubot [options]"
Expand All @@ -49,6 +51,9 @@ Parser.on "enable-slash", (opt) ->
Parser.on "alias", (opt, value) ->
Options.alias = value

Parser.on "disable-httpd", (opt) ->
Options.enableHttpd = false

Parser.on "help", (opt, value) ->
console.log Parser.toString()
process.exit 0
Expand Down Expand Up @@ -81,7 +86,12 @@ else if Options.version

else
adapterPath = Path.resolve __dirname, "..", "src", "adapters"
robot = Hubot.loadBot adapterPath, Options.adapter, Options.name

robot = Hubot.loadBot adapterPath,
Options.adapter,
Options.enableHttpd,
Options.name

robot.enableSlash = Options.enableSlash
robot.alias = Options.alias

Expand Down
14 changes: 7 additions & 7 deletions src/robot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Robot
# dispatch them to matching listeners.
#
# path - String directory full of Hubot scripts to load.
constructor: (adapterPath, adapter, name = "Hubot") ->
constructor: (adapterPath, adapter, httpd, name = "Hubot") ->
@name = name
@brain = new Brain
@alias = false
Expand All @@ -24,10 +24,9 @@ class Robot
@listeners = []
@loadPaths = []
@enableSlash = false

@logger = new Log process.env.HUBOT_LOG_LEVEL or "info"

@setupConnect()
@setupConnect() if httpd
@loadAdapter adapterPath, adapter if adapter?

# Public: Specify a router and callback to register as Connect middleware.
Expand Down Expand Up @@ -148,14 +147,16 @@ class Robot
# Sets up basic authentication if parameters are provided
#
# Returns: nothing.
setupConnect: () ->
setupConnect: ->
user = process.env.CONNECT_USER
pass = process.env.CONNECT_PASSWORD

@connect = Connect()
if user and pass
@connect.use Connect.basicAuth(user, path)

@connect.listen process.env.PORT

# Load the adapter Hubot is going to use.
#
# path - A String of the path to adapter if local.
Expand Down Expand Up @@ -265,7 +266,6 @@ class Robot
matchedUsers

run: ->
@connect.listen process.env.PORT
@adapter.run()

shutdown: ->
Expand All @@ -279,7 +279,7 @@ class Robot.Message
constructor: (@user, @done = false) ->

# Indicates that no other Listener should be called on this object
finish: () ->
finish: ->
@done = true

class Robot.TextMessage extends Robot.Message
Expand Down Expand Up @@ -390,7 +390,7 @@ class Robot.Response
# Public: Tell the message to stop dispatching to listeners
#
# Returns nothing.
finish: () ->
finish: ->
@message.finish()

# Public: Creates a scoped http client with chainable methods for
Expand Down

0 comments on commit 5fd81c3

Please sign in to comment.