Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Feature: added ability for verbose and quiet output
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankruijter committed Aug 16, 2020
1 parent fd54f5b commit 6eb1e75
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 92 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: php
php:
- '7.2'
- '7.3'
- '7.4'

Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.0.0 - 2020-08-16
### Added
- Ability to output additional context.
- Ability to suppress all output.
- Ability to select an output mode.

## 1.0.5 - 2020-06-08
### Fixed
- Compatibility with ulrack/services version 3.0
Expand All @@ -29,7 +35,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Created the initial implementation of the command package.

# Versions
- [1.0.5 > Unreleased](https://github.com/ulrack/command/compare/1.0.5...HEAD)
- [2.0.0 > Unreleased](https://github.com/ulrack/command/compare/2.0.0...HEAD)
- [1.0.5 > 2.0.0](https://github.com/ulrack/command/compare/1.0.5...2.0.0)
- [1.0.4 > 1.0.5](https://github.com/ulrack/command/compare/1.0.4...1.0.5)
- [1.0.3 > 1.0.4](https://github.com/ulrack/command/compare/1.0.3...1.0.4)
- [1.0.2 > 1.0.3](https://github.com/ulrack/command/compare/1.0.2...1.0.3)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ This main object can then be supplied to the [router](src/Common/Router/RouterIn

All sub-commands can be added to their respective command configuration instance.
This can be infinitely deep.
All command configuration instances have the `no-interaction` and `help` flag configured by default.
All command configuration instances have the following flags configured by default:
- `no-interaction`, disables the interactive reader.
- `help`, displays help text for the execution of the command.
- `verbose`, displays additional information about the execution of the command.
- `quiet`, suppresses the output of the command.
Sub-commands of a parent command can be executed by separating them by a space.

### [Router](src/Component/Router/CommandRouter.php)
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"prefer-stable": true,
"minimum-stability": "stable",
"require": {
"php": "^7.2",
"php": "^7.3",
"grizz-it/configuration": "^1.1",
"grizz-it/enum": "^1.0",
"grizz-it/task": "^1.0",
"grizz-it/validator": "^1.0",
"ulrack/cli": "^1.0",
Expand Down Expand Up @@ -46,7 +47,7 @@
]
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"squizlabs/php_codesniffer": "^3.4"
"phpunit/phpunit": "^9.3",
"squizlabs/php_codesniffer": "^3.5"
}
}
23 changes: 12 additions & 11 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResult="false">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
55 changes: 46 additions & 9 deletions src/Common/Command/OutputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Ulrack\Command\Common\Command;

use GrizzIt\Task\Common\TaskListInterface;
use Ulrack\Command\Common\Command\OutputModeEnum;
use Ulrack\Cli\Common\Generator\FormGeneratorInterface;

interface OutputInterface
Expand All @@ -17,31 +18,46 @@ interface OutputInterface
*
* @param string $input
* @param string $style
* @param bool $verbose
*
* @return void
*/
public function write(string $input, string $style = 'text'): void;
public function write(
string $input,
string $style = 'text',
bool $verbose = false
): void;

/**
* Writes the output in a line to the user.
*
* @param string $input
* @param string $style
* @param bool $verbose
*
* @return void
*/
public function writeLine(string $input, string $style = 'text'): void;
public function writeLine(
string $input,
string $style = 'text',
bool $verbose = false
): void;

/**
* Writes a mutable line to the user.
* The next writer will overwrite this line.
*
* @param string $input
* @param string $style
* @param bool $verbose
*
* @return void
*/
public function overWrite(string $input, string $style = 'text'): void;
public function overWrite(
string $input,
string $style = 'text',
bool $verbose = false
): void;

/**
* Retrieves the form generator.
Expand All @@ -56,13 +72,15 @@ public function getFormGenerator(): FormGeneratorInterface;
* @param string $content
* @param bool $newLine
* @param string $styleKey
* @param bool $verbose
*
* @return void
*/
public function outputText(
string $content,
bool $newLine = true,
string $styleKey = 'text'
string $styleKey = 'text',
bool $verbose = false
): void;

/**
Expand All @@ -74,6 +92,7 @@ public function outputText(
* @param string $style
* @param string $boxStyle
* @param string $keyStyle
* @param bool $verbose
*
* @return void
*/
Expand All @@ -83,20 +102,23 @@ public function outputTable(
string $tableCharacters = 'table-characters',
string $style = 'table-style',
string $boxStyle = 'table-box-style',
string $keyStyle = 'table-key-style'
string $keyStyle = 'table-key-style',
bool $verbose = false
): void;

/**
* Output a list.
*
* @param array $items
* @param string $style
* @param bool $verbose
*
* @return void
*/
public function outputList(
array $items,
string $style = 'list'
string $style = 'list',
bool $verbose = false
): void;

/**
Expand All @@ -105,13 +127,15 @@ public function outputList(
* @param array $items
* @param string $keyStyle
* @param string $descriptionStyle
* @param bool $verbose
*
* @return void
*/
public function outputExplainedList(
array $items,
string $keyStyle = 'explained-list-key',
string $descriptionStyle = 'explained-list-description'
string $descriptionStyle = 'explained-list-description',
bool $verbose = false
): void;

/**
Expand All @@ -121,14 +145,16 @@ public function outputExplainedList(
* @param string $style
* @param string $padding
* @param string $margin
* @param bool $verbose
*
* @return void
*/
public function outputBlock(
string $content,
string $style = 'block',
string $padding = 'block-padding',
string $margin = 'block-margin'
string $margin = 'block-margin',
bool $verbose = false
): void;

/**
Expand All @@ -138,13 +164,24 @@ public function outputBlock(
* @param string $progressCharacters
* @param string $textStyle
* @param string $progressStyle
* @param bool $verbose
*
* @return void
*/
public function outputProgressBar(
TaskListInterface $taskList,
string $progressCharacters = 'progress-characters',
string $textStyle = 'progress-text',
string $progressStyle = 'progress-bar'
string $progressStyle = 'progress-bar',
bool $verbose = false
): void;

/**
* Sets the output mode.
*
* @param OutputModeEnum $outputMode
*
* @return void
*/
public function setOutputMode(OutputModeEnum $outputMode): void;
}
33 changes: 33 additions & 0 deletions src/Common/Command/OutputModeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
*/

namespace Ulrack\Command\Common\Command;

use GrizzIt\Enum\Enum;

/**
* @method static OutputModeEnum OUTPUT_MODE_NORMAL()
* @method static OutputModeEnum OUTPUT_MODE_VERBOSE()
* @method static OutputModeEnum OUTPUT_MODE_QUIET()
*/
class OutputModeEnum extends Enum
{
/**
* Outputs normally.
*/
public const OUTPUT_MODE_NORMAL = 'normal';

/**
* Displays additional context to the output.
*/
public const OUTPUT_MODE_VERBOSE = 'verbose';

/**
* Suppresses all output.
*/
public const OUTPUT_MODE_QUIET = 'quiet';
}
Loading

0 comments on commit 6eb1e75

Please sign in to comment.