diff --git a/README.org b/README.org index f639c0f..36d1e12 100644 --- a/README.org +++ b/README.org @@ -1,13 +1,29 @@ * Report cli - Automate generating invoices. - + Automate generating invoices from youtrack reports and other time-tracking + related functionality. ** Usage + + ~./rprt.php rprt -y -p -s~ + + This command would send an invoice for last month created from the template + file and last month report from youtrack as an email attachment. ** Install/Getting started - Get ~.phar~ file, run configuration wizzard. + Get ~.phar~ file, run configuration wizzard (planned for version 1.0). + + Before version 1.0 is released you have to navigate into ~/app~ directory + and call command through ~.rprt.php~ file. + +*** Requirements + + 1. You have to create a youtrack API token. + 2. You have to configure rprt-cli app. + - Default folder that app checks for config file is in ~~/.config/rprt-cli/~. + 3. You have to allow [[https://support.google.com/accounts/answer/6010255?hl=en][less secure applications]] in your gmail if you are using + that email provider. ** Specs A simple Console Command that prints out monthly report from youtrack. @@ -41,6 +57,24 @@ - remove errors from reports ** Plan + +*** current + + 1. For Version 1.0 + - Track Command (track time from your cli) + - Report Command (read reports) + - Improve code and code style + - ~.phar~ file for simple app shipping + 2. Version 2.0 + - Implement templateing service + - Further code improvements + - Configuration Wizzard + 3. Version 3.0 + - Emacs package to track directly from orgmode + - Add tests + + +*** old 1. Basic structure of the cli-app 1. App preparation - nice specifications @@ -59,6 +93,7 @@ 1. Invoice output 2. configuration wizard + ** Learning - https://www.youtube.com/watch?v=aCqM9YnjTe0 - Choices (~new ChoiceQuestion~) diff --git a/app/src/Commands/RprtCommand.php b/app/src/Commands/RprtCommand.php index 28c837c..c922872 100644 --- a/app/src/Commands/RprtCommand.php +++ b/app/src/Commands/RprtCommand.php @@ -95,6 +95,12 @@ class RprtCommand extends Command InputOption::VALUE_NONE, 'Send pdf export via email to recipient.' ); + $this->addOption( + 'send-to', + 'r', + InputOption::VALUE_REQUIRED, + 'Comma separated list of recipients that should get the exported pdf.' + ); } protected function execute(InputInterface $input, OutputInterface $output) : int @@ -127,6 +133,9 @@ class RprtCommand extends Command } if ($send = $input->getOption('send') && $output_path) { // Send email to configured address. + if ($recipients = $input->getOption('send-to')) { + $this->mailer->setRecipients(explode(',', $recipients)); + } $this->mailer->sendDefaultMail($output_path); } diff --git a/app/src/Utils/Mailer/MailerService.php b/app/src/Utils/Mailer/MailerService.php index 9fe9b1b..82341bd 100644 --- a/app/src/Utils/Mailer/MailerService.php +++ b/app/src/Utils/Mailer/MailerService.php @@ -39,7 +39,7 @@ class MailerService implements MailerInterface { $this->pdf = $pdf; } - public function setRecipents(array $to): void + public function setRecipients(array $to): void { $this->to = $to; } @@ -66,10 +66,41 @@ class MailerService implements MailerInterface { return $this->{$property}; } + protected function getRecipients() { + if (!isset($this->to)) { + $value = $this->config->get('email.to', FALSE); + if (!$value) { + $value = explode(',', readline('Provide recipients\' emails separated by a comma: ')); + } + $this->to = $value; + } + return $this->to; + } + + private function readPassword($prompt = "Enter Password:") { + echo $prompt; + system('stty -echo'); + $password = trim(fgets(STDIN)); + system('stty echo'); + return $password; + } + + protected function getPasswordProperty() { + if (!isset($this->password)) { + $value = $this->config->get('email.password', FALSE); + if (!$value) { + $value = $this->readPassword(); + } + $this->password = $value; + } + return $this->password; + } + + public function sendMail(string $from, array $to, string $subject, string $text, array $attachment = []): void { $email = new Email(); $email->from($from); - $email->to($to[0]); + $email->to(...$to); // @TODO use twig for templates. Create new template service. // https://github.com/symfony/mailer $email->subject($subject); @@ -91,9 +122,10 @@ class MailerService implements MailerInterface { public function getTransport() { // @TODO remove username and password from config. $username = rawurlencode($this->getProperty('username')); - $password = rawurlencode($this->getProperty('password')); + $password = rawurlencode($this->getPasswordProperty()); // If your credentials contain special characters, you must URL-encode them. - $mailer_dsn = "gmail+smtp://{$username}:{$password}@default"; + // $mailer_dsn = "gmail+smtp://{$username}:{$password}@default"; + $mailer_dsn = "gmail://{$username}:{$password}@localhost?encryption=tls&auth_mode=oauth"; return Transport::fromDsn($mailer_dsn); }