Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,28 @@ const emitSuccess = message => console.log(green(` ✔ Sucesso: ${message}`));
const emitError = message => console.log(red(` ✗ Erro: ${message}`));

function cli(args) {
gemidao(args)
.then(() => {
emitSuccess(args.sms ? 'sms enviado!' : 'chamada efetuada!');
})
.catch(pipe(prop('message'), emitError));
if(args.bidirecional){
send(args);
var temp = args.de;
args.de = args.para;
args.para = temp;
send(args);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sugestão de código utilizando ES6:

send(args);
let { de: para, para: de } = args;
send({...args, de, para});

É importante ressalvar que send() é assíncrono. Eu não sei como a API se comportaria com duas chamadas simultâneas. Talvez fosse bacana você encadear a promise.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pela minha configuração do linter atual, até o let vai ser barrado. Ele vai permitir somente const, e vai bloquear reatribuição/mutabilidade (paradigma funcional).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O ideal também é que a lógica aconteça dentro do gemidao.js, que é onde lida com os argumentos. O cli.js só despacha.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opa, bem lembrado, @haskellcamargo. Nem cheguei a ler as configs do Lint ainda.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ele tá barrando let, var, try, for e while, pelo que lembro.

}else{
send(args);
}

}

function bidirecional(args){

}

function send(arg){
gemidao(arg)
.then(() => {
emitSuccess(arg.sms ? 'sms enviado!' : 'chamada efetuada!');
})
.catch(pipe(prop('message'), emitError));
}

cli(yargs
Expand All @@ -34,6 +51,10 @@ cli(yargs
describe: 'Se definido, será enviado um SMS ao invés de uma chamada',
type: 'boolean'
})
.option('bidirecional', {
describe: 'Defini se a chamada deve ser enviada para ambos os números',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sugestão de descrição: Se definido, realiza uma nova ligação, desta vez com o de/para invertidos

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Defini -> Define

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

type: 'boolean'
})
.demandOption(['para', 'token'])
.locale('pt_BR')
.strict()
Expand Down