Skip to content

Commit

Permalink
Updating to latest Minicli
Browse files Browse the repository at this point in the history
  • Loading branch information
erikaheidi committed May 30, 2023
1 parent 2bc4164 commit 11cc3ee
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 93 deletions.
16 changes: 10 additions & 6 deletions Command/Create/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@

namespace librarianphp\Create;

use Minicli\FileNotFoundException;
use Minicli\Stencil;
use Minicli\Command\CommandController;
use Minicli\Input;

class ContentController extends CommandController
{
/**
* @throws FileNotFoundException
*/
public function handle(): void
{
if (!$this->getApp()->config->has('stencil_dir')) {
$this->getApp()->getPrinter()->error("You must define a stencil_dir config option.");
$this->error("You must define a stencil_dir config option.");
return;
}

if (!$this->getApp()->config->has('stencil_locations')) {
$this->getApp()->getPrinter()->error("You must define a stencil_locations array config option.");
$this->error("You must define a stencil_locations array config option.");
return;
}

Expand All @@ -30,10 +34,10 @@ public function handle(): void

$input = new Input(' ');

$this->getPrinter()->info("Content Title: ");
$this->info("Content Title: ");
$title = $input->read();

$this->getPrinter()->info("Content Description: ");
$this->info("Content Description: ");
$description = $input->read();

$content = $stencil->applyTemplate($template_name, [
Expand All @@ -44,7 +48,7 @@ public function handle(): void
$save_locations = $this->getApp()->config->stencil_locations;

if (!array_key_exists($template_name, $save_locations)) {
$this->getPrinter()->error("Save location not found for template $template_name");
$this->error("Save location not found for template $template_name");
return;
}

Expand All @@ -53,7 +57,7 @@ public function handle(): void
$file = fopen($path . '/' . $save_name, 'a+');

fwrite($file, $content);
$this->getPrinter()->info("Content generated at " . $path . '/' . $save_name);
$this->info("Content generated at " . $path . '/' . $save_name);
}

public function slugify($title)
Expand Down
4 changes: 2 additions & 2 deletions Command/Create/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DefaultController extends CommandController
{
public function handle(): void
{
$this->getPrinter()->info("./librarian create [subcommand]", true);
$this->getPrinter()->info("Run \"./librarian create content\" to create a content file based on a template.");
$this->info("./librarian create [subcommand]", true);
$this->info("Run \"./librarian create content\" to create a content file based on a template.");
}
}
Loading

0 comments on commit 11cc3ee

Please sign in to comment.