-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There was already a CLI, but it wasn't very complete and wasn't actually exposed under the "bin" field
- Loading branch information
1 parent
5d23486
commit 626453e
Showing
6 changed files
with
344 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,62 @@ | ||
#! /usr/bin/env nod | ||
#! /usr/bin/env node | ||
|
||
import getDatabase, {killDatabase} from '.'; | ||
import * as commands from './commands'; | ||
const command = process.argv[2]; | ||
const args = process.argv.slice(3); | ||
|
||
// tslint:disable-next-line:no-unused-expression | ||
require('yargs') | ||
.command( | ||
'start', | ||
'start the database', | ||
(yargs: any) => { | ||
// TODO: take options as CLI parameters | ||
}, | ||
async (argv: any) => { | ||
try { | ||
const {databaseURL} = await getDatabase({detached: true}); | ||
console.info(databaseURL); | ||
} catch (ex) { | ||
console.error(ex.stack || ex); | ||
process.exit(1); | ||
} | ||
}, | ||
) | ||
.command( | ||
'kill', | ||
'kill the database', | ||
(yargs: any) => { | ||
// TODO: take options as CLI parameters | ||
const hasHelpFlag = args.includes('--help') || args.includes('-h'); | ||
if (hasHelpFlag) { | ||
commands.help(); | ||
process.exit(0); | ||
} | ||
|
||
switch (command) { | ||
case 'start': | ||
if (hasHelpFlag) { | ||
commands.help('start'); | ||
} else { | ||
handle(commands.start(args)); | ||
} | ||
break; | ||
case 'run': | ||
if (hasHelpFlag) { | ||
commands.help('run'); | ||
} else { | ||
handle(commands.run(args)); | ||
} | ||
break; | ||
case 'stop': | ||
if (hasHelpFlag) { | ||
commands.help('stop'); | ||
} else { | ||
handle(commands.stop(args)); | ||
} | ||
break; | ||
case 'help': | ||
commands.help(args[0]); | ||
break; | ||
default: | ||
commands.help(); | ||
if (!hasHelpFlag) { | ||
console.error( | ||
`Unexpected command ${command}, expected one of "start" or "help"`, | ||
); | ||
process.exit(1); | ||
} | ||
break; | ||
} | ||
|
||
function handle(v: Promise<number>) { | ||
if (!v) { | ||
process.exit(0); | ||
} | ||
v.then( | ||
(value) => { | ||
process.exit(value); | ||
}, | ||
async (argv: any) => { | ||
try { | ||
await killDatabase(); | ||
} catch (ex) { | ||
console.error(ex.stack || ex); | ||
process.exit(1); | ||
} | ||
(ex) => { | ||
console.error(ex.stack || ex); | ||
process.exit(1); | ||
}, | ||
) | ||
.strict() | ||
.demandCommand() | ||
.help().argv; | ||
); | ||
} |
Oops, something went wrong.