import { run } from 'runjs'

export function echo (...args) {
  console.log('ECHO', args, this.options)
}

export function testapi () {
  run('ls -al | cat')
}

export function testerror (async) {
  if (async) {
    run('node ./error_script.js', {async: true}).catch((error) => {
      console.log('ERROR', error)
    })
  } else {
    run('node ./error_script.js')
  }
}

export function testcolor () {
  run('node ./color_script.js')
  run('node ./color_script.js', {async: true})
}

export function testserver () {
  run('http-server', {async: true})
}

export function testasync () {
  run('ls -al | cat', {async: true}).then((data) => {
    console.log('DATA', data)
  }).catch((error) => {
    console.log('ERROR', error)
  })
}

export async function testasyncawait () {
  await run('ls -al | cat', {async: true}).then((data) => {
    console.log('DATA', data)
  })
  console.log('After AWAIT message')
}

export const n1 = {
  nested1 () {
    console.log('Nested task nr 1 executed!')
  },

  'nested2:echo': () => {
    console.log('Nested task nr 2 executed!')
  },

  all () {
    n1.nested1()
    n1['nested2:echo']()
  }
}


echo.help = 'Simple echo task'
n1.nested1.help = 'Description of nested task nr 1'
n1['nested2:echo'].help = 'Description of nested task nr 2'

@@ -1012,16 +1012,26 @@
 echo': (
+arg1, arg2
 ) =%3E %7B%0A 
@@ -1141,17 +1141,16 @@
 %0A  %7D%0A%7D%0A%0A
-%0A
 echo.hel
@@ -1282,10 +1282,23 @@
 ask nr 2
+%5Cnsecond line
 '%0A

Improve runfile in babel sandbox