 exports.run = () ->
   argv = require("optimist")
     .usage(usage)
+
     .boolean(["l", "link"]).alias("l", "link")
     .describe("l", "install components as symlinks (useful for development)")
-    .boolean("list")
-    .describe("list", "when running the 'test' command, just list tests")
+
+    .boolean("listtests")
+    .describe("listtests", "when running the 'test' command, just list tests")
+
+    .string(["t", "templatepath"]).alias("t", "templatepath")
+    .describe("t", "when running 'build', command, specify the templatepath")
+
+    .string(["j", "contextjsonname"]).alias("j", "contextjsonname")
+    .default("contextjsonname", "csi-context.json")
+    .describe("j", "when running 'build', command, specify the name of the context json")
+
+    .string(["s", "staticpath"]).alias("s", "staticpath")
+    .describe("s", "when running 'build', command, specify the staticpath")
+
+    .string(["b", "baseurl"]).alias("b", "baseurl")
+    .default("baseurl", "/static")
+    .describe("b", "when running 'build', command, specify the baseurl")
+
+    .check((argv) ->
+      if argv._[0] is 'build'
+        for arg in ['templatepath', 'staticpath']
+          if not argv[arg]
+            throw Error "'#{arg}' option must be defined for 'build' command"
+    )
+
     .alias("h", "help")
+
     .argv
 
   command = argv._[0]

  for test in tests
    console.log("http://#{host}:#{port}/#{test.replace(/\.js$/, "")}")

commands =

  install: () ->

    listTests tests, host, port

  template: (cmd, args...) ->
    templateCommands[cmd] getConfig()

  build: () ->
    commands.install()

    staticDirName = join testDirectory(), "static"
    provide argv.staticpath
    wrench.copyDirSyncRecursive staticDirName, argv.staticpath

    config = getConfig()
    templateObj = _.reduce(templateCommands, ((templateObj, cmd, name) ->
      templateObj[name] = templateCommands[name](config)
      return templateObj
    ), {})
    provide argv.templatepath
    contextjsonname = join(argv.templatepath, argv.contextjsonname)
    write contextjsonname, JSON.stringify(templateObj)


commandNames = _.reduce(commands, ((memo, v, k) ->
