Skip to content

Commit

Permalink
Fixing merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSteveKing committed May 16, 2023
2 parents 218b42c + fcedd4b commit 93edf1b
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 168 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* text=auto

/.art export-ignore
/.github export-ignore
/tests export-ignore
.editorconfig export-ignore
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Minicli Framework
<div align="center">
<p>
<img src="https://github.com/minicli/framework/raw/main/art/minicli.png" alt="Minicli" width="150"/>
<h1>Minicli Framework</h1>
</p>
</div>

This repo contains the source code for the Minicli Framework - a great way to extend the core minicli application.
Binary file added art/minicli.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions src/Configuration/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Minicli\Framework\Configuration;

use Minicli\Framework\Contracts\Theme\ThemeContract;

final class Config
{
/**
* @param string $path
* @param class-string<ThemeContract>|null $theme
* @param bool $debug
*/
public function __construct(
private readonly string $path,
private readonly ?string $theme = null,
private readonly bool $debug = false,
) {
}

/**
* @return array{path:string,theme:class-string<ThemeContract>|null,debug:bool}
*/
public function toArray(): array
{
return [
'path' => $this->path,
'theme' => $this->theme,
'debug' => $this->debug,
];
}

/**
* @param array{path:string,theme:class-string<ThemeContract>|null,debug:bool|null} $data
* @return Config
*/
public static function make(array $data): Config
{
return new Config(
path: $data['path'],
theme: $data['theme'],
debug: $data['debug'] ?? false,
);
}
}
79 changes: 32 additions & 47 deletions src/Contracts/Theme/ThemeContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,38 @@

namespace Minicli\Framework\Contracts\Theme;

namespace Minicli\Framework\Contracts\Theme;
namespace Minicli\Framework\Theme;

interface ThemeContract
{
/**
* Default style
* @return array<int,MiniEnum>
*/
public function default(): array;

/**
* Alternative style for Default
* @return array<int,MiniEnum>
*/
public function alt(): array;

/**
* Error style
* @return array<int,MiniEnum>
*/
public function error(): array;

/**
* Alternative style for Error
* @return array<int,MiniEnum>
*/
public function errorAlt(): array;

/**
* Success style
* @return array<int,MiniEnum>
*/
public function success(): array;

/**
* Alternative style for Success
* @return array<int,MiniEnum>
*/
public function successAlt(): array;

/**
* Info style
* @return array<int,MiniEnum>
*/
public function info(): array;

/**
* Alternative style for Info
* @return array<int,MiniEnum>
*/
public function infoAlt(): array;
public function default(): ThemeStyle;

public function alt(): ThemeStyle;

public function error(): ThemeStyle;

public function errorAlt(): ThemeStyle;

public function warning(): ThemeStyle;

public function warningAlt(): ThemeStyle;

public function success(): ThemeStyle;

public function successAlt(): ThemeStyle;

public function info(): ThemeStyle;

public function infoAlt(): ThemeStyle;

public function bold(): ThemeStyle;

public function dim(): ThemeStyle;

public function italic(): ThemeStyle;

public function underline(): ThemeStyle;

public function invert(): ThemeStyle;
}
98 changes: 14 additions & 84 deletions src/Minicli.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,113 +4,43 @@

namespace Minicli\Framework;

use Minicli\Framework\Commands\PendingCommand;
use Minicli\Framework\Configuration\Config;
use Minicli\Framework\Contracts\Output\PrinterContract;
use Minicli\Framework\Contracts\Theme\ThemeContract;
use Minicli\Framework\DI\Container;
use Minicli\Framework\Exceptions\BindingResolutionException;
use Minicli\Framework\Output\Engine;
use Minicli\Framework\Output\Printer\DefaultPrinter;
use Minicli\Framework\Theme\Catalog\DefaultTheme;
use ReflectionException;

final class Minicli extends Container
{
public const VERSION = '0.0.1';

public string $name;

public array|string $path;

public ThemeContract $theme;

public bool $debug = false;

public Engine $engine;
public function __construct(
protected readonly Config $config,
) {
parent::__construct();
}

/**
* @param string $name
* @param array|string $path
* @param null|class-string<ThemeContract> $theme
* @param string $path
* @param class-string<ThemeContract>|null $theme
* @param bool $debug
* @param PrinterContract|null $printer
* @return Minicli
*/
public static function boot(
string $name,
array|string $path,
null|string $theme,
string $path,
?string $theme,
bool $debug = false,
null|PrinterContract $printer = null,
): Minicli {
return Minicli::getInstance()->name(
name: $name,
)->path(
$config = new Config(
path: $path,
)->theme(
theme: $theme ?? DefaultTheme::class,
)->debug(
theme: $theme,
debug: $debug,
)->buildEngine(
printer: $printer ?? new DefaultPrinter(),
);
}

public function name(string $name): Minicli
{
$this->name = $name;

return $this;
}

public function path(string|array $path): Minicli
{
$this->path = $path;

return $this;
}

/**
* @param class-string<ThemeContract> $theme
* @return $this
* @throws BindingResolutionException|ReflectionException
*/
public function theme(string $theme): Minicli
{
/**
* @var ThemeContract $instance
*/
$instance = $this->make(
abstract: $theme,
);

$this->theme = $instance;

return $this;
}

public function debug(bool $debug): Minicli
{
$this->debug = $debug;

return $this;
}

public function buildEngine(PrinterContract $printer): Minicli
{
$this->engine = new Engine(
theme: $this->theme,
printer: $printer,
);

return $this;
}

public function run(array $arguments = []): void
{
$command = PendingCommand::build(
arguments: $arguments,
return new Minicli(
config: $config
);
// build and send command through engine.
}
}
Loading

0 comments on commit 93edf1b

Please sign in to comment.