   @version: ->
     'v' + JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8'))['version']
 
-  @run: (done, file_generator_cb, analytics = false, homepage = false) ->
+  @run: ->
 
-    metadocopts =
-      _ : []
+    optimist = require('optimist')
+      .usage("""
+      Usage: $0 [options] [source_files]
+      """)
+      .options('o',
+        alias: 'output-dir'
+        describe: 'The output directory'
+        default: './doc'
+      )
+      .options('d',
+        alias: 'debug'
+        describe: 'Show stacktraces and converted CoffeeScript source'
+        boolean: true
+        default: false
+      )
+      .options('h',
+        alias: 'help'
+        describe: 'Show the help'
+      )
 
-    try
-      if fs.existsSync('.metadocopts')
-        configs = fs.readFileSync '.metadocopts', 'utf8'
+    argv = optimist.argv
 
-        for config in configs.split('\n')
-          # Key value configs
-          if option = /^-{1,2}([\w-]+)\s+(['"])?(.*?)\2?$/.exec config
-            metadocopts[option[1]] = option[3]
-          # Boolean configs
-          else if bool = /^-{1,2}([\w-]+)\s*$/.exec config
-            metadocopts[bool[1]] = true
-          # Argv configs
-          else if config isnt ''
-            metadocopts._.push config
+    if argv.h
+      console.log optimist.help()
+      return
 
+    options =
+      inputs: argv._
+      output: argv.o
 
-      Async.parallel {
-        inputs:  @detectSources
-        readme:  @detectReadme
-        extras:  @detectExtras
-        name:    @detectName
-        tag:     @detectTag
-        origin:  @detectOrigin
-      },
-      (err, defaults) =>
+    parser = new Parser(options)
+    metadataSlugs = []
 
-        extraUsage = if defaults.extras.length is 0 then '' else  "- #{ defaults.extras.join ' ' }"
+    for input in options.inputs
+      continue unless (fs.existsSync || path.existsSync)(input)
 
-        optimist = require('optimist')
-          .usage("""
-          Usage:   $0 [options] [source_files [- extra_files]]
-          Default: $0 [options] #{ defaults.inputs.join ' ' } #{ extraUsage }
-          """)
-          .options('o',
-            alias     : 'output-dir'
-            describe  : 'The output directory'
-            default   : metadocopts['output-dir'] || metadocopts.o || './doc'
-          )
-          .options('d',
-            alias     : 'debug'
-            describe  : 'Show stacktraces and converted CoffeeScript source'
-            boolean   : true
-            default   : metadocopts.debug || metadocopts.d  || false
-          )
-          .options('h',
-            alias     : 'help'
-            describe  : 'Show the help'
-          )
+      # collect probable package.json path
+      package_json_path = path.join(input, 'package.json')
+      stats = fs.lstatSync input
+      absoluteInput = path.resolve(process.cwd(), input)
 
-        argv = optimist.argv
+      if stats.isDirectory()
+        for filename in walkdir.sync input
+          if @isAcceptableFile(filename) and @isInAcceptableDir(absoluteInput, filename)
+            console.log absoluteInput, filename
 
-        if argv.h
-          console.log optimist.help()
+            try
+              relativePath = filename
+              relativePath = path.normalize(filename.replace(process.cwd(), ".#{path.sep}")) if filename.indexOf(process.cwd()) == 0
+              parser.parseFile relativePath
+            catch error
+              throw error if options.debug
+              console.log "Cannot parse file #{ filename }@#{error.location.first_line}: #{ error.message }"
+      else
+        if @isAcceptableFile(input)
+          try
+            parser.parseFile input
+          catch error
+            throw error if options.debug
+            console.log "Cannot parse file #{ filename }@#{error.location.first_line}: #{ error.message }"
 
-        else
-          options =
-            inputs: []
-            output: argv.o
-            json: argv.j || ""
-            extras: []
-            name: argv.n
-            readme: argv.r
-            title: argv.title
-            quiet: argv.q
-            private: argv.private
-            internal: argv.internal
-            noOutput: argv.noOutput
-            missing: argv.missing
-            verbose: argv.v
-            debug: argv.d
-            cautious: argv.cautious
-            homepage: homepage
-            analytics: analytics || argv.a
-            tag: defaults.tag
-            origin: defaults.origin
-            metadata: argv.metadata
-            stability: argv.stability
+      metadataSlugs.push @generateMetadataSlug(package_json_path, parser, options)
 
-          extra = false
+    @writeMetadata(metadataSlugs, options)
 
-          # ignore params if metadoc has not been started directly
-          args = if argv._.length isnt 0 and /.+metadoc$/.test(process.argv[1]) then argv._ else metadocopts._
+  @isAcceptableFile = (filePath) ->
+    for file in BLACKLIST_FILES
+      return false if new RegExp(file+'$').test(filePath)
 
-          for arg in args
-            if arg is '-'
-              extra = true
-            else
-              if extra then options.extras.push(arg) else options.inputs.push(arg)
+    filePath.match(/\._?coffee$/)
 
-          options.inputs = defaults.inputs if options.inputs.length is 0
-          options.extras = defaults.extras if options.extras.length is 0
+  @isInAcceptableDir = (inputPath, filePath) ->
+    # is in the root of the input?
+    return true if path.join(inputPath, path.basename(filePath)) is filePath
 
-          parser = new Parser(options)
-          metadataSlugs = []
+    # is under src, lib, or app?
+    acceptableDirs = (path.join(inputPath, dir) for dir in SRC_DIRS)
+    for dir in acceptableDirs
+      return true if filePath.indexOf(dir) == 0
 
-          for input in options.inputs
-            continue unless (fs.existsSync || path.existsSync)(input)
-
-            # collect probable package.json path
-            package_json_path = path.join(input, 'package.json')
-            stats = fs.lstatSync input
-
-            if stats.isDirectory()
-              for filename in walkdir.sync input
-                if filename.match /\._?coffee$/
-                  console.log filename
-                  # try
-                  relativePath = filename
-                  relativePath = path.normalize(filename.replace(process.cwd(), ".#{path.sep}")) if filename.indexOf(process.cwd()) == 0
-                  shortPath = relativePath.replace(path.resolve(process.cwd(), input) + path.sep, '')
-                  # don't parse Gruntfile.coffee, specs, or anything not in a src dir
-                  parser.parseFile relativePath if _.some(SRC_DIRS, (dir) -> ///^#{dir}///.test(shortPath))
-                  # catch error
-                  #   throw error if options.debug
-                  #   console.log "Cannot parse file #{ filename }@#{error.location.first_line}: #{ error.message }"
-            else
-              if input.match /\._?coffee$/
-                try
-                  parser.parseFile input
-                catch error
-                  throw error if options.debug
-                  console.log "Cannot parse file #{ filename }@#{error.location.first_line}: #{ error.message }"
-
-            metadataSlugs.push @generateMetadataSlug(package_json_path, parser, options)
-
-          @writeMetadata(metadataSlugs, options)
-          done() if done
-
-    catch error
-      done(error) if done
-      console.log "Cannot generate documentation: #{ error.message }"
-      throw error
+    false
 
   @writeMetadata: (metadataSlugs, options) ->
     fs.writeFileSync path.join(options.output, 'metadata.json'), JSON.stringify(metadataSlugs, null, "    ")

{exec} = require 'child_process'

SRC_DIRS = ['src', 'lib', 'app']

module.exports = class MetaDoc
  @Parser: Parser

        file = path.relative(package_json_path, composite_main)
        file = file.substring(1, file.length) if file.match /^\.\./
        return file
