<commit_before><?hh //strict

/**
 * This file is part of hhpack/migrate.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace HHPack\Migrate\Application;

use HHPack\Getopt as cli;
use HHPack\Getopt\Parser\{ OptionParser };
use HHPack\Migrate\{ File, Output, Logger };
use HHPack\Migrate\Logger\{ PlainLogger, ColoredLogger };

final class MigrateApplication
{

    const PROGRAM_NAME = 'migrate';
    const PROGRAM_VERSION = '1.0.0';
    const PROGRAM_LICENCE = 'The MIT Licence';

    private bool $help = false;
    private bool $version = false;
    private bool $outputColor = true;
    private string $configurationPath = 'config/database.json';
    private OptionParser $optionParser;
    private ImmMap<string, Command> $commands;

    public function __construct(
        private Output $output
    )
    {
        $this->optionParser = cli\optparser([
            cli\take_on(['-c', '--config'], 'FILE', 'Path of configuration file', ($path) ==> {
                $this->configurationPath = $path;
            }),
            cli\on(['--no-color'], 'If specified, color output will not be performed', () ==> {
                $this->outputColor = false;
            }),
            cli\on(['-h', '--help'], 'Display help message', () ==> {
                $this->help = true;
            }),
            cli\on(['-v', '--version'], 'Display version', () ==> {
                $this->version = true;
            })
        ]);

        $this->commands = ImmMap {
            "up" => new UpCommand(),
            "down" => new DownCommand()
        };
    }

    public function run(Traversable<string> $argv): void
    {
        $cliArgv = Vector::fromItems($argv)->skip(1);
        $remainArgv = Vector::fromItems($this->optionParser->parse($cliArgv));

        if ($this->help || !$remainArgv->containsKey(0)) {
            $this->displayHelp();
        } else if ($this->version) {
            $this->displayVersion();
        } else {
            $commandName = $remainArgv->at(0);
            $this->runCommand($commandName, $argv);
        }
    }

    private function runCommand(string $name, Traversable<string> $argv): void
    {
        if (!$this->commands->contains($name)) {
            $this->displayHelp();
        } else {
            $loader = new ConfigurationLoader(File\absolutePath(getcwd() . $this->configurationPath));
            $env = getenv('HHVM_ENV') ? getenv('HHVM_ENV') : 'development';
            $configuration = $loader->load($env);
<commit_msg>fix --version option<commit_after><?hh //strict

/**
 * This file is part of hhpack/migrate.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace HHPack\Migrate\Application;

use HHPack\Getopt as cli;
use HHPack\Getopt\Parser\{ OptionParser };
use HHPack\Migrate\{ File, Output, Logger };
use HHPack\Migrate\Logger\{ PlainLogger, ColoredLogger };

final class MigrateApplication
{

    const PROGRAM_NAME = 'migrate';
    const PROGRAM_VERSION = '1.0.0';
    const PROGRAM_LICENCE = 'The MIT Licence';

    private bool $help = false;
    private bool $version = false;
    private bool $outputColor = true;
    private string $configurationPath = 'config/database.json';
    private OptionParser $optionParser;
    private ImmMap<string, Command> $commands;

    public function __construct(
        private Output $output
    )
    {
        $this->optionParser = cli\optparser([
            cli\take_on(['-c', '--config'], 'FILE', 'Path of configuration file', ($path) ==> {
                $this->configurationPath = $path;
            }),
            cli\on(['--no-color'], 'If specified, color output will not be performed', () ==> {
                $this->outputColor = false;
            }),
            cli\on(['-h', '--help'], 'Display help message', () ==> {
                $this->help = true;
            }),
            cli\on(['-v', '--version'], 'Display version', () ==> {
                $this->version = true;
            })
        ]);

        $this->commands = ImmMap {
            "up" => new UpCommand(),
            "down" => new DownCommand()
        };
    }

    public function run(Traversable<string> $argv): void
    {
        $cliArgv = Vector::fromItems($argv)->skip(1);
        $remainArgv = Vector::fromItems($this->optionParser->parse($cliArgv));

        if ($this->help) {
            $this->displayHelp();
        } else if ($this->version) {
            $this->displayVersion();
        } else if (!$remainArgv->containsKey(0)) {
            $this->displayHelp();
        } else {
            $commandName = $remainArgv->at(0);
            $this->runCommand($commandName, $argv);
        }
    }

    private function runCommand(string $name, Traversable<string> $argv): void
    {
        if (!$this->commands->contains($name)) {
            $this->displayHelp();
        } else {
            $loader = new ConfigurationLoader(File\absolutePath(getcwd() . $this->configurationPath));
            $env = getenv('HHVM_ENV') ? getenv('HHVM_ENV') : 'development';
            $configuration = $loader->load($env);

{'fraction_non_alphanumeric': 0.15580952380952381, 'fraction_numerical': 0.002285714285714286, 'mean_word_length': 2.281875, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5434520', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1523, 'n_words': 363}