Short code fixes and Readme update.

master
Lio Novelli 2021-10-03 16:45:40 +02:00
parent aeae9ea490
commit df662c3eb9
3 changed files with 83 additions and 7 deletions

View File

@ -1,13 +1,29 @@
* Report cli * Report cli
Automate generating invoices. Automate generating invoices from youtrack reports and other time-tracking
related functionality.
** Usage ** 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 ** 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 ** Specs
A simple Console Command that prints out monthly report from youtrack. A simple Console Command that prints out monthly report from youtrack.
@ -41,6 +57,24 @@
- remove errors from reports - remove errors from reports
** Plan ** 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. Basic structure of the cli-app
1. App preparation 1. App preparation
- nice specifications - nice specifications
@ -59,6 +93,7 @@
1. Invoice output 1. Invoice output
2. configuration wizard 2. configuration wizard
** Learning ** Learning
- https://www.youtube.com/watch?v=aCqM9YnjTe0 - https://www.youtube.com/watch?v=aCqM9YnjTe0
- Choices (~new ChoiceQuestion~) - Choices (~new ChoiceQuestion~)

View File

@ -95,6 +95,12 @@ class RprtCommand extends Command
InputOption::VALUE_NONE, InputOption::VALUE_NONE,
'Send pdf export via email to recipient.' '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 protected function execute(InputInterface $input, OutputInterface $output) : int
@ -127,6 +133,9 @@ class RprtCommand extends Command
} }
if ($send = $input->getOption('send') && $output_path) { if ($send = $input->getOption('send') && $output_path) {
// Send email to configured address. // Send email to configured address.
if ($recipients = $input->getOption('send-to')) {
$this->mailer->setRecipients(explode(',', $recipients));
}
$this->mailer->sendDefaultMail($output_path); $this->mailer->sendDefaultMail($output_path);
} }

View File

@ -39,7 +39,7 @@ class MailerService implements MailerInterface {
$this->pdf = $pdf; $this->pdf = $pdf;
} }
public function setRecipents(array $to): void public function setRecipients(array $to): void
{ {
$this->to = $to; $this->to = $to;
} }
@ -66,10 +66,41 @@ class MailerService implements MailerInterface {
return $this->{$property}; 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 { public function sendMail(string $from, array $to, string $subject, string $text, array $attachment = []): void {
$email = new Email(); $email = new Email();
$email->from($from); $email->from($from);
$email->to($to[0]); $email->to(...$to);
// @TODO use twig for templates. Create new template service. // @TODO use twig for templates. Create new template service.
// https://github.com/symfony/mailer // https://github.com/symfony/mailer
$email->subject($subject); $email->subject($subject);
@ -91,9 +122,10 @@ class MailerService implements MailerInterface {
public function getTransport() { public function getTransport() {
// @TODO remove username and password from config. // @TODO remove username and password from config.
$username = rawurlencode($this->getProperty('username')); $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. // 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); return Transport::fromDsn($mailer_dsn);
} }