<commit_before><?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright © 2011-2012 by <NAME> (<EMAIL>) -->
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:prg="http://xsd.nore.fr/program" version="1.0">
	<output method="text" encoding="utf-8" />
	<param name="interpreter">
		<text>php</text>
	</param>
	<include href="../../../ns/xsl/languages/php.xsl" />

	<template match="prg:databinding/prg:variable">
		<value-of select="normalize-space(.)" />
	</template>

	<template match="/">
		<text>#!/usr/bin/env </text>
		<value-of select="$interpreter" />
		<text><![CDATA[
<?php
$scriptPath = dirname (realpath(__FILE__));
require_once ($scriptPath . "/program-lib.php" );

function echol ($line)
{
	echo ($line . "\n");
}

function echolist ($iterable)
{
	$first = true;
	foreach ($iterable as $a)
	{
		if (!$first)
		{
			echo ", ";
		}
		$first = false;
		echo "\"" . $a . "\"";
	}

	echo "\n";
}

function echovalue($arg)
{
	if (is_bool($arg))
	{
		echo (($arg) ? "True" : "False");
	}
	else if (is_array($arg))
	{
		echo implode(" ", $arg);
	}
	else
	{
		echo $arg;
	}
	echo ("\n");
}

$info = new \TestProgramInfo;
$parser = new \Parser($info);
$result = $parser->parse($_SERVER["argv"]);

$args = $_SERVER["argv"];
array_shift($args);

echo "CLI: ";
echolist ($args);
echol ("Value count: " . $result->valueCount());
echo ("Values: "); echolist ($result);
$errors = $result->getMessages(\Message::ERROR);
$errorCount = count($errors);
echol ("Error count: " . $errorCount);
if ($errorCount > 0)
{
	foreach ($args as $arg)
	{
		if ($arg == "__msg__")
		{
			echol ("Errors");
			foreach ($errors as $e)
			{
				echol ("- " . $e);
			}
		}
	}
} 
echol ("Subcommand: " . ($result->subcommandName ? $result->subcommandName : ""));  
]]></text>
		<!-- Global args -->
		<if test="/prg:program/prg:options"><commit_msg>unittest: add __help__ special argument in template program to display help<commit_after><?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright © 2011-2012 by <NAME> (<EMAIL>) -->
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:prg="http://xsd.nore.fr/program" version="1.0">
	<output method="text" encoding="utf-8" />
	<param name="interpreter">
		<text>php</text>
	</param>
	<include href="../../../ns/xsl/languages/php.xsl" />

	<template match="prg:databinding/prg:variable">
		<value-of select="normalize-space(.)" />
	</template>

	<template match="/">
		<text>#!/usr/bin/env </text>
		<value-of select="$interpreter" />
		<text><![CDATA[
<?php
$scriptPath = dirname (realpath(__FILE__));
require_once ($scriptPath . '/program-lib.php' );

function echol ($line)
{
	echo ($line . PHP_EOL);
}

function echolist ($iterable)
{
	$first = true;
	foreach ($iterable as $a)
	{
		if (!$first)
		{
			echo ', ';
		}
		$first = false;
		echo '"' . $a . '"';
	}

	echo (PHP_EOL);
}

function echovalue($arg)
{
	if (is_bool($arg))
	{
		echo (($arg) ? 'True' : 'False');
	}
	else if (is_array($arg))
	{
		echo implode(' ', $arg);
	}
	else
	{
		echo $arg;
	}
	echo (PHP_EOL);
}

$info = new \TestProgramInfo;
$parser = new \Parser($info);
$result = $parser->parse($_SERVER['argv']);

$args = $_SERVER['argv'];
array_shift($args);

echo 'CLI: ';
echolist ($args);
echol ('Value count: ' . $result->valueCount());
echo ('Values: '); echolist ($result);
$errors = $result->getMessages(\Message::ERROR);
$errorCount = count($errors);
echol ('Error count: ' . $errorCount);
if ($errorCount > 0)
{
	foreach ($args as $arg)
	{
		if ($arg == '__msg__')
		{
			echol ('Errors');
			foreach ($errors as $e)
			{
				echol ('- ' . $e);
			}
		}
		if ($arg == '__help__')
		{
			$usage = new UsageFormat;
			$usage->format = UsageFormat::DETAILED_TEXT;
			echo ($info->usage($usage));   
		}
	}
} 
echol ('Subcommand: ' . ($result->subcommandName ? $result->subcommandName : ''));  
]]></text>
		<!-- Global args -->
		<if test="/prg:program/prg:options">
{'fraction_non_alphanumeric': 0.23486994591810456, 'fraction_numerical': 0.010301313417460727, 'mean_word_length': 3.777367773677737, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 2, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '7650914', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1486, 'n_words': 303}