import program from 'commander'

function lazyRequire(path) {
  return function (...args) {
    const res = require(path)(...args)

    if (res.catch) {
      res.catch(err => {
        console.error(err.stack)
      })
    }
  }
}

program
  .command('launch [services...]')
  .option('-e, --environment [env]', 'set the environment name to be used [dev]', 'dev')
  .description('Launches the given services in an environment')
  .action(lazyRequire('./launch'))
  .on('--help', () => console.log(`
  This will prompt you for the services that you want to bring up.
  You can optionally provide the names of services to bring up which will disable the interactive prompt.
  `))

program
  .command('help')
  .alias('*')
  .action(() => program.help())

export default program

@@ -39,24 +39,155 @@
 ion 
-lazyRequire(path
+wrapper(res) %7B%0A  if (res.catch) %7B%0A    res.catch(err =%3E %7B%0A      console.error(err.stack)%0A    %7D)%0A  %7D%0A%0A  return res%0A%7D%0A%0Afunction basicCliWrapper(fnName
 ) %7B%0A
@@ -195,16 +195,22 @@
  return 
+async 
 function
@@ -211,16 +211,31 @@
 nction (
+maybeServices, 
 ...args)
@@ -251,131 +251,601 @@
 nst 
-res = require(path)(...args)%0A%0A    if (res.catch) %7B%0A      res.catch(err =%3E %7B%0A        console.error(err.stack
+%7B getEnvironment %7D = require('../environment')%0A%0A    const opts = args.length === 0 ? maybeServices : args%5Bargs.length - 1%5D%0A    const otherArgs = args.slice(0, args.length - 1)%0A    const envName = opts.environment%0A%0A    const returnVal = await wrapper(getEnvironment(envName)%5BfnName%5D(%0A      Array.isArray(maybeServices) && maybeServices.length === 0%0A        ? undefined%0A        : maybeServices,%0A      ...otherArgs,%0A    ))%0A%0A    if (returnVal != null) %7B%0A      console.log(returnVal
 )%0A    
+%7D%0A
   %7D
-)%0A    %7D
+%0A%7D%0A%0Afunction lazyRequire(path) %7B%0A  return function (...args) %7B%0A    return wrapper(require(path)(...args))
 %0A  %7D
@@ -1295,16 +1295,228 @@
 %0A  %60))%0A%0A
+program%0A  .command('ps')%0A  .option('-e, --environment %5Benv%5D', 'set the environment name to be used %5Bdev%5D', 'dev')%0A  .description('Lists the running services for an environment')%0A  .action(basicCliWrapper('ps'))%0A%0A
 program%0A

Add ps to cli