#!/usr/bin/env node
import program from "commander";
import say from "say";
import quotes from "../index.js";
const quote = quotes.random();
import { readFile } from 'fs/promises';
const pkg = JSON.parse(await readFile(new URL("../package.json", import.meta.url)));
const { log } = console;

program
.version(`${pkg.name} v${pkg.version}`)
.usage('desmotivacional [options]')
.option('-a, --all', 'Displays all phrases')
.option('-s, --speak', 'Speak a unique quote')

program.on('--help', function(){});

program.parse(process.argv);
const options = program.opts();

if(program.args.length >= 1) program.help();

const speakQuote = () => {
    say.speak(quote, 1.0, err => {
        if(err) log(err);
    });
}
if(options.speak) speakQuote();
(options && options.all) ? log(quotes.all.sort().join("\n")) : log(quote);


@@ -13,16 +13,17 @@
 nv node%0A
+%0A
 import p
@@ -341,17 +341,17 @@
 %0A.usage(
-'
+%22
 desmotiv
@@ -367,17 +367,17 @@
 options%5D
-'
+%22
 )%0A.optio
@@ -378,17 +378,17 @@
 .option(
-'
+%22
 -a, --al
@@ -392,33 +392,34 @@
 -all
-', 'Displays all ph
+%22, %22Exibe todas as f
 rases
-'
+%22
 )%0A.o
@@ -428,45 +428,46 @@
 ion(
-'-s
+%22-l
 , --
-speak', 'Speak a unique quote'
+listen%22, %22Ou%C3%A7a uma frase %C3%BAnica%22
 )%0A%0Ap
@@ -480,16 +480,16 @@
 .on(
-'
+%22
 --help
-'
+%22
 , fu
@@ -616,21 +616,22 @@
 %0A%0Aconst 
-speak
+listen
 Quote = 
@@ -724,20 +724,22 @@
 ons.
-speak) speak
+listen) listen
 Quot
@@ -818,9 +818,8 @@
 quote);%0A
-%0A

change speak to listen a quote and define options cli in pt-br