#!/usr/bin/env node
import { exit } from 'process'

import readPkgUp from 'read-pkg-up'
import UpdateNotifier from 'update-notifier'

import { addErrorHandler } from '../errors/handler.js'
import * as instructions from '../main.js'

import { parseInput } from './input.js'

// Run a server instruction, from the CLI
const startCli = async function () {
  await checkUpdate()

  const measures = []
  const { instruction, opts } = parseInput({ measures })

  await instructions[instruction]({ ...opts, measures })
}

const checkUpdate = async function () {
  const { packageJson } = await readPkgUp({ cwd: __dirname, normalize: false })
  UpdateNotifier({ pkg: packageJson }).notify()
}

// If an error is thrown, print error's description,
// then exit with exit code 1
const cliErrorHandler = function ({ message, description = message }) {
  console.error(`Error: ${description}`)

  exit(1)
}

const eStartCli = addErrorHandler(startCli, cliErrorHandler)

eStartCli()

@@ -26,28 +26,95 @@
 t %7B 
-exit %7D from 'process
+dirname %7D from 'path'%0Aimport %7B exit %7D from 'process'%0Aimport %7B fileURLToPath %7D from 'url
 '%0A%0Ai
@@ -118,26 +118,39 @@
 %0A%0Aimport
+ %7B
  readP
-kgUp
+ackageUpAsync %7D
  from 'r
@@ -593,47 +593,158 @@
 %0A%7D%0A%0A
-const checkUpdate = async function () %7B
+// TODO: use static JSON imports once those are possible%0Aconst checkUpdate = async function () %7B%0A  const cwd = dirname(fileURLToPath(import.meta.url))
 %0A  c
@@ -781,29 +781,27 @@
 eadP
-kgUp(%7B cwd: __dirname
+ackageUpAsync(%7B cwd
 , no

Upgrade read-pkg-up