text: #!/usr/bin/env node
  
  'use strict';
  
  const fs = require('fs');
  const [name] = process.argv.slice(2);
  
  if (!name)
      usage();
  else if (/^(-v|--v)$/.test(name))
      version();
  else if (/^(-h|--help)$/.test(name))
      help();
  else
      checkFile(name, (error) => {
          if (!error)
              return main(name);
          
          console.error(error.message);
      });
  
  function getPath(name) {
      const reg = /^(~|\/)/;
      
      if (!reg.test(name))
          name = process.cwd() + '/' + name;
      
      return name;
  }
  
  function main(name) {
      const filename = getPath(name);
      const DIR = __dirname + '/../html/';
      const deepword = require('..');
      const http = require('http');
      const express = require('express');
      const io = require('socket.io');
      
      const app = express();
      const server = http.createServer(app);
      
      const {env} = process;
      
      const port = env.PORT || /* c9           */
                      env.app_port || /* nodester     */
                      env.VCAP_APP_PORT || /* cloudfoundry */
                      1337;
      const ip = env.IP || /* c9           */
                  '0.0.0.0';
      
      app .use(express.static(DIR))
          .use(deepword({
              diff: true,
              zip: true,
          }));
      
      server.listen(port, ip);
      
      const socket = io.listen(server);
      const edSocket = deepword.listen(socket);
      
      edSocket.on('connection', () => {
          fs.readFile(name, 'utf8', (error, data) => {
              if (error)
                  console.error(error.message);
              else
                  edSocket.emit('file', filename, data);
          });
      });
      
      console.log('url: http://' + ip + ':' + port);
  }
  
  function checkFile(name, callback) {
      fs.stat(name, (error, stat) => {
          let msg;
          
          if (error && error.code === 'ENOENT')
              msg = Error(`no such file or directory: '${name}'`);
          else if (stat.isDirectory())
              msg = Error(`'${name}' is directory`);
          
          callback(msg);
      });
  }
  
  function version() {
      console.log(`v${info().version}`);
  }
  
  function info() {
      return require('../package');
  }
  
  function usage() {
      console.log(`Usage: ${info().name} [filename]`);
  }
  
  function help() {
      const bin = require('../json/bin');
      
      usage();
      console.log('Options:');
      
      for (const name of Object.keys(bin)) {
          console.log(`  ${name} ${bin[name]}`);
      }
  }
  