Esempio n. 1
0
    /**
     * test wrap() indenting
     *
     * @return void
     */
    public function testWrapIndent()
    {
        $text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
        $result = String::wrap($text, array('width' => 33, 'indent' => "\t", 'indentAt' => 1));
        $expected = <<<TEXT
This is the song that never ends.
\tThis is the song that never ends.
\tThis is the song that never ends.
TEXT;
        $this->assertTextEquals($expected, $result);
    }
Esempio n. 2
0
 /**
  * Get the help as formatted text suitable for output on the command line.
  *
  * @param int $width The width of the help output.
  * @return string
  */
 public function text($width = 72)
 {
     $parser = $this->_parser;
     $out = [];
     $description = $parser->description();
     if (!empty($description)) {
         $out[] = String::wrap($description, $width);
         $out[] = '';
     }
     $out[] = __d('cake_console', '<info>Usage:</info>');
     $out[] = $this->_generateUsage();
     $out[] = '';
     $subcommands = $parser->subcommands();
     if (!empty($subcommands)) {
         $out[] = __d('cake_console', '<info>Subcommands:</info>');
         $out[] = '';
         $max = $this->_getMaxLength($subcommands) + 2;
         foreach ($subcommands as $command) {
             $out[] = String::wrap($command->help($max), ['width' => $width, 'indent' => str_repeat(' ', $max), 'indentAt' => 1]);
         }
         $out[] = '';
         $out[] = __d('cake_console', 'To see help on a subcommand use <info>`cake %s [subcommand] --help`</info>', $parser->command());
         $out[] = '';
     }
     $options = $parser->options();
     if (!empty($options)) {
         $max = $this->_getMaxLength($options) + 8;
         $out[] = __d('cake_console', '<info>Options:</info>');
         $out[] = '';
         foreach ($options as $option) {
             $out[] = String::wrap($option->help($max), ['width' => $width, 'indent' => str_repeat(' ', $max), 'indentAt' => 1]);
         }
         $out[] = '';
     }
     $arguments = $parser->arguments();
     if (!empty($arguments)) {
         $max = $this->_getMaxLength($arguments) + 2;
         $out[] = __d('cake_console', '<info>Arguments:</info>');
         $out[] = '';
         foreach ($arguments as $argument) {
             $out[] = String::wrap($argument->help($max), ['width' => $width, 'indent' => str_repeat(' ', $max), 'indentAt' => 1]);
         }
         $out[] = '';
     }
     $epilog = $parser->epilog();
     if (!empty($epilog)) {
         $out[] = String::wrap($epilog, $width);
         $out[] = '';
     }
     return implode("\n", $out);
 }
Esempio n. 3
0
 /**
  * Wrap a block of text.
  * Allows you to set the width, and indenting on a block of text.
  *
  * ### Options
  *
  * - `width` The width to wrap to. Defaults to 72
  * - `wordWrap` Only wrap on words breaks (spaces) Defaults to true.
  * - `indent` Indent the text with the string provided. Defaults to null.
  *
  * @param string $text Text the text to format.
  * @param int|array $options Array of options to use, or an integer to wrap the text to.
  * @return string Wrapped / indented text
  * @see String::wrap()
  * @link http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::wrapText
  */
 public function wrapText($text, $options = [])
 {
     return String::wrap($text, $options);
 }