         process.stdout.write '\u2717\n'.red
         callback("#{stdout}\n#{stderr}".red)
 
-  publishPackage: (options) ->
+  publishPackage: (options, callback) ->
     process.stdout.write 'Publishing '
     try
       {name, version} = CSON.readFileSync(CSON.resolve('package')) ? {}

    @fork @atomNpmPath, publishArgs, (code, stderr='', stdout='') ->
      if code is 0
        process.stdout.write '\u2713\n'.green
        options.callback()
      else
        process.stdout.write '\u2717\n'.red
        options.callback("#{stdout}\n#{stderr}".red)

  run: (options) ->
    version = options.commandArgs.shift()
    if version
      @versionPackage version, (error) =>
        if error?
          options.callback(error)
        else
          @publishPackage(options)
    else
      @publishPackage(options)

  constructor: ->
    @userConfigPath = config.getUserConfigPath()
    @atomNpmPath = require.resolve('npm/bin/npm-cli')

  parseOptions: (argv) ->
    options = optimist(argv)
    options.usage """

      Usage: apm publish [<newversion> | major | minor | patch | build]

      Publish a new version of the package in the current working directory.

      If a new version or version increment is specified than a new Git tag is
      created and the package.json file is updated with that new version before
      it is published to the apm registry.

      Run `apm available` to see all the currently published packages.
    """
    options.alias('h', 'help').describe('help', 'Print this usage message')
    options.string('tag').describe('tag', 'Specify a tag to publish under')
    options.boolean('force').describe('force', 'Force publish')

  showHelp: (argv) -> @parseOptions(argv).showHelp()

  versionPackage: (version, callback) ->
    process.stdout.write 'Preparing and tagging a new version '
