<commit_before><?php

namespace EPFL\Menus\CLI;

if (! defined( 'ABSPATH' )) {
    die( 'Access denied.' );
}

use \WP_CLI;
use \WP_CLI_Command;

require_once(dirname(__DIR__) . '/lib/i18n.php');
use function EPFL\I18N\___;

require_once(__DIR__ . '/epfl-menus.php');
use \EPFL\Menus\ExternalMenuItem;

add_filter('epfl_rest_rewrite_connect_to', function($hostport, $host, $port) {
    // TODO: this is not a way to go through life, son
    if ($hostport === "www.epfl.ch:443") {
        return "httpd-www:8443";
    } elseif ($hostport === "jahia2wp-httpd:443") {
        return "jahia2wp-httpd:8443";
    } else {
        return $hostport;
    }
}, 10, 3);


class EPFLMenusCLICommand extends WP_CLI_Command
{
    public static function hook () {
        WP_CLI::add_command('epfl-menus', get_called_class());
    }

    public function refresh () {
        WP_CLI::log(___('Enumerating menus on filesystem...'));
        $local = ExternalMenuItem::load_from_filesystem();
        WP_CLI::log(sprintf(___('... Success, found %d local menus'),
                            count($local)));
<commit_msg>Add config loading when using WP CLI to refresh<commit_after><?php

namespace EPFL\Menus\CLI;

if (! defined( 'ABSPATH' )) {
    die( 'Access denied.' );
}

use \WP_CLI;
use \WP_CLI_Command;

require_once(dirname(__DIR__) . '/lib/i18n.php');
use function EPFL\I18N\___;

require_once(__DIR__ . '/epfl-menus.php');
use \EPFL\Menus\ExternalMenuItem;

add_filter('epfl_rest_rewrite_connect_to', function($hostport, $host, $port) {
    // TODO: this is not a way to go through life, son
    if ($hostport === "www.epfl.ch:443") {
        return "httpd-www:8443";
    } elseif ($hostport === "jahia2wp-httpd:443") {
        return "jahia2wp-httpd:8443";
    } else {
        return $hostport;
    }
}, 10, 3);


class EPFLMenusCLICommand extends WP_CLI_Command
{
    public static function hook () {
        WP_CLI::add_command('epfl-menus', get_called_class());
    }

    public function refresh () {
        WP_CLI::log(___('Enumerating menus on filesystem...'));
        $local = ExternalMenuItem::load_from_filesystem();
        WP_CLI::log(sprintf(___('... Success, found %d local menus'),
                            count($local)));

        WP_CLI::log(___('Enumerating menus in config file...'));
        $local = ExternalMenuItem::load_from_config_file();
        WP_CLI::log(sprintf(___('... Success, found %d site-configured menus'),
                            count($local)));

{'fraction_non_alphanumeric': 0.15427882683808758, 'fraction_numerical': 0.018481317798312576, 'mean_word_length': 3.0686274509803924, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2004663', 'n_tokens_mistral': 885, 'n_tokens_neox': 849, 'n_words': 178}