<commit_before>#!/usr/bin/env php
<?php
/**
 * File containing the ezp.php script.
 *
 * @copyright Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 * @version //autogentag//
 */

/**
 * This script is the root script to eZ Publish bin/php scripts.
 *
 * Unlike individual scripts, it offers bash completion through the /etc/bash_completion.d/ezp script.
 *
 * Return values:
 * - 0: OK
 * - 1: unknown command
 * - 2: unknown script
 *
 * Arguments:
 * - _scripts: returns a space separated list of available scripts
 * - _args <script>: returns the space separated list of available arguments for <script>
 */

define( 'WORD_SEPARATOR', "\n" );

require 'autoload.php';

$input = new ezcConsoleInput();
try {
    $input->process();
} catch( ezcConsoleOptionException $e )
{
    die( $e->getMessage() );
}

$arguments = $input->getArguments();
if ( count( $arguments ) === 0 )
{
    return 1;
}

switch( $arguments[0] )
{
    // scripts list
    case '_scripts':
        echo implode( WORD_SEPARATOR, getScripts() );
        break;

    // arguments list for a script
    case '_args':
        if ( !isset( $arguments[1] ) )
            return 2;
        $script = getScript( $arguments[1] );
        if ( $script == false )
            return 2;
        $arguments = getArguments( $script );
        if ( $arguments == false )
            return 2;
        echo implode( WORD_SEPARATOR, $arguments );
        break;

    // execute the script
    default:
        $script = getScript( array_shift( $arguments ) );
        $arguments = implode( ' ', $arguments );
        passthru( "$script $arguments" );
}

/**
 * Returns the list of available scripts, without the ez/ezp prefix and without the .php extension
 *
 * Spaces are added at the of each script name for better completion
 *
 * @return array
 */
function getScripts()<commit_msg>ezp.php: refactored completion string output<commit_after>#!/usr/bin/env php
<?php
/**
 * File containing the ezp.php script.
 *
 * @copyright Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 * @version //autogentag//
 */

/**
 * This script is the root script to eZ Publish bin/php scripts.
 *
 * Unlike individual scripts, it offers bash completion through the /etc/bash_completion.d/ezp script.
 *
 * Return values:
 * - 0: OK
 * - 1: unknown command
 * - 2: unknown script
 *
 * Arguments:
 * - _scripts: returns a space separated list of available scripts
 * - _args <script>: returns the space separated list of available arguments for <script>
 */

require 'autoload.php';

$input = new ezcConsoleInput();
try {
    $input->process();
} catch( ezcConsoleOptionException $e )
{
    die( $e->getMessage() );
}

$arguments = $input->getArguments();
if ( count( $arguments ) === 0 )
{
    return 1;
}

switch( $arguments[0] )
{
    // scripts list
    case '_scripts':
        complete( getScripts() );
        break;

    // arguments list for a script
    case '_args':
        if ( !isset( $arguments[1] ) )
            return 2;
        $script = getScript( $arguments[1] );
        if ( $script == false )
            return 2;

        $arguments = getArguments( $script );
        if ( $arguments == false )
            return 2;

        complete( $arguments );
        break;

    case '_siteaccess_list':
        $siteaccessList = eZINI::
        complete( $siteaccessList );
        break;

    // execute the script
    default:
        $script = getScript( array_shift( $arguments ) );
        $arguments = implode( ' ', $arguments );
        passthru( "$script $arguments" );
}

/**
 * Formats and output a words list for completion
 * @param array $words
 */
function complete( array $words )
{
    echo implode( "\n", $words );
}

/**
 * Returns the list of available scripts, without the ez/ezp prefix and without the .php extension
 *
 * Spaces are added at the of each script name for better completion
 *
 * @return array
 */
function getScripts()
{'fraction_non_alphanumeric': 0.12853658536585366, 'fraction_numerical': 0.010731707317073172, 'mean_word_length': 2.661607142857143, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5942763', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1218, 'n_words': 408}