2013-05-24 12 views
7

Voglio creare un CLI per creare utenti admin ho la messa a punto del modello utente in API/modelli/user.jsVele js utilizzando modelli al di fuori del server web

e nella CLI su

var User, program; 

program = require("commander"); 

User = require("../api/models/User"); 

program.version("0.0.1"); 

program.command("create_user").description("Create a user into database").action(function() { 
    return console.log(User); 
}); 

program.parse(process.argv); 

utente il registro è:

User = { 
     attributes: { 
     username: "string", 
     password: "string", 
     } 
    }; 

e nessun metodo di linea di galleggiamento disponibile per l'uso.

risposta

2

Se qualcuno ha bisogno di questo:

sails = require("sails"); 
sails.lift({ 
    log: { 
    level: 'silent' 
    } 
}, function() { 
    User.create(obj); 
    process.stdin.destroy(); 
}); 
5

È possibile utilizzare sails run <command>.

sufficiente creare <appPath>/commands/index.js con questo contenuto:

module.exports = { 
    testcommand: function (done) { 
     // .. your code 
     console.log('this is my testcommand'); 
     done(); 
    } 
} 

ora è possibile eseguire sails run testcommand

+0

Nizza, che le versioni supporta questo? – carlitux

+0

0.9.x supporta questo – Edy

+0

In vele 0.10.0 'vele run' è stato rimosso. – Edy

Problemi correlati