Skip to content

Commit

Permalink
log command success or failure
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Apr 24, 2023
1 parent 1bfda1f commit 0f88e09
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ export async function runme () {
return cp.spawn(command, { stdio: 'inherit', shell: true, env: process.env })
}

/**
* fetch all commands
*/
const commands = await findAllCommand()

/**
* run new Runme CLI (experimental)
*/
export async function runme2 () {
const spawnOpts: SpawnOptions = { stdio: 'inherit', shell: true, env: process.env }
const commands = await findAllCommand()
const params = process.argv.slice(2)
const flags = params.filter((p) => p.startsWith('-'))
const ids = params.filter((p) => !p.startsWith('-'))
Expand All @@ -49,12 +44,19 @@ export async function runme2 () {
}
}

function runById (id: string, commands: string[][]) {
async function runById (id: string, commands: string[][]) {
const [file] = commands.find(([, cmdId]) => cmdId === id) || []

if (!file) {
throw new Error(`Runme cell with id "${id}" not found`)
}

return run(file, id)
console.log(`🏃 Run "${id}" from ${file.replace(process.cwd(), '')}`)
const result = await run(file, id)
const resultMessage = result.exitCode === 0
? `✅ Command "${id}" succeeded!\n`
: `🚨 Failed: "${result.stdout || result.stderr || `Program failed with exit code ${result.exitCode}`}"\n`
console.log(resultMessage)

return result
}

0 comments on commit 0f88e09

Please sign in to comment.