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 {
11+
812 async run ( ) {
9- const { flags} = this . parse ( SequelizeTinkerCommand )
13+ const { flags, args } = this . parse ( SequelizeTinkerCommand )
1014
1115 if ( flags === _initialFlags ) {
1216 return
1317 }
1418
19+ // show config
20+ if ( args . firstArg === 'config' ) {
21+ jq . run ( '.' , getAll ( ) , { input : 'json' } )
22+ . then ( ( output ) => {
23+ this . log ( output )
24+ } )
25+ . catch ( ( error ) => {
26+ this . error ( error )
27+ } )
28+ return
29+ }
30+
31+ if ( flags [ 'models-path' ] ) {
32+ setModelsPath ( flags [ 'models-path' ] )
33+ }
34+
35+ // repl entry
1536 const replUtil = new Repl ( { initializeContext} )
1637 replUtil . start ( )
1738 }
@@ -27,6 +48,17 @@ SequelizeTinkerCommand.flags = {
2748 // add --help flag to show CLI version
2849 help : flags . help ( { char : 'h' } ) ,
2950 // name: flags.string({ char: 'n', description: 'name to print' })
51+ 'models-path' : flags . string ( { char : 'p' , description : `Set Sequelize models's dir path.` } ) ,
3052}
3153
54+ SequelizeTinkerCommand . args = [
55+ { name : 'firstArg' } ,
56+ { name : 'secondArg' } ,
57+ ]
58+ SequelizeTinkerCommand . examples = [
59+ '$ sequelize-tinker' ,
60+ '$ sequelize-tinker --models-path ./src/models' ,
61+ '$ sequelize-tinker config' ,
62+ ]
63+
3264module . exports = SequelizeTinkerCommand
0 commit comments