'use strict'
var http = require('http')
var minimist = require('minimist')
var url = require('url')

class ValidationError extends Error {
}

class Command {
  run (options) {
    var optionNames = Object.keys(options)
    if (!this.validate(optionNames)) throw new ValidationError()

    return String(this.core(this.convertOptions(options)))
  }

  convertOptions (options) {
    return Object.keys(options).reduce((memo, key) => {
      memo[key] = String(options[key])
      return memo
    }, {})
  }

  validate (optionNames) {
    if (Array.isArray(this.requiredOptions)) {
      return this.requiredOptions.every(requiredOption =>
        optionNames.indexOf(requiredOption) > -1
      )
    } else {
      return true
    }
  }
}

class Runner {
  constructor (command) {
    this.command = command
  }
}

class CLI extends Runner {
  options () {
    var args = minimist(process.argv.slice(2))

    var options = Object.assign({}, args)
    delete options._
    return Command.prototype.convertOptions(options)
  }

  run () {
    console.log(this.command.run(this.options()))
  }
}

class Server extends Runner {
  constructor (command) {
    super(command)
    this.server = http.createServer(this.callback.bind(this))
  }

  options (req) {
    return url.parse(req.url, true).query
  }

  callback (req, res) {
    res.setHeader('content-type', 'text/plain')
    res.writeHead(200)
    res.end(`${this.command.run(this.options(req))}\n`)
  }

  close () {
    this.server.close()
  }

  run () {
    this.server.listen(3000)
  }
}

module.exports = { ValidationError, Command, Runner, CLI, Server }

@@ -151,16 +151,114 @@
 mmand %7B%0A
+  isSubset (subset, superset) %7B%0A    return subset.every(item =%3E superset.indexOf(item) %3E -1)%0A  %7D%0A%0A
   run (o
@@ -629,20 +629,24 @@
 ) %7B%0A    
-if (
+return !
 Array.is
@@ -676,52 +676,44 @@
 ons)
-) %7B
+ %7C%7C
 %0A      
-return this.requiredOptions.every(
+       this.isSubset(this.
 requ
@@ -726,19 +726,10 @@
 tion
- =%3E%0A       
+s,
  opt
@@ -740,82 +740,9 @@
 ames
-.indexOf(requiredOption) %3E -1%0A      )%0A    %7D else %7B%0A      return true%0A    %7D
+)
 %0A  %7D

Refactor Command#validate()