11const { Command, flags} = require ( '@oclif/command' )
2+ const jq = require ( 'node-jq' )
3+
24const Repl = require ( './repl' )
35const { initializeContext} = require ( './sequelize-context' )
6+ const { setModelsPath, getAll} = require ( './config' )
47
58const _initialFlags = { }
69
710class SequelizeTinkerCommand extends Command {
811 async run ( ) {
9- const { flags} = this . parse ( SequelizeTinkerCommand )
12+ const { flags, args } = this . parse ( SequelizeTinkerCommand )
1013
1114 if ( flags === _initialFlags ) {
1215 return
1316 }
1417
18+ // show config
19+ if ( args . firstArg === 'config' ) {
20+ jq . run ( '.' , getAll ( ) , { input : 'json' } )
21+ . then ( output => {
22+ this . log ( output )
23+ } )
24+ . catch ( error => {
25+ this . error ( error )
26+ } )
27+ return
28+ }
29+
30+ if ( flags [ 'models-path' ] ) {
31+ setModelsPath ( flags [ 'models-path' ] )
32+ }
33+
34+ // repl entry
1535 const replUtil = new Repl ( { initializeContext} )
1636 replUtil . start ( )
1737 }
@@ -27,6 +47,17 @@ SequelizeTinkerCommand.flags = {
2747 // add --help flag to show CLI version
2848 help : flags . help ( { char : 'h' } ) ,
2949 // name: flags.string({ char: 'n', description: 'name to print' })
50+ 'models-path' : flags . string ( { char : 'p' , description : 'Set Sequelize models\'s dir path.' } ) ,
3051}
3152
53+ SequelizeTinkerCommand . args = [
54+ { name : 'firstArg' } ,
55+ { name : 'secondArg' } ,
56+ ]
57+ SequelizeTinkerCommand . examples = [
58+ '$ sequelize-tinker' ,
59+ '$ sequelize-tinker --models-path ./src/models' ,
60+ '$ sequelize-tinker config' ,
61+ ]
62+
3263module . exports = SequelizeTinkerCommand
0 commit comments