Browse Source

Moved the `Program` and `Version` classes to the `which` package

tags/v1.0.0
Cédric Belin 1 month ago
parent
commit
0f6351308b
16 changed files with 256 additions and 33 deletions
  1. +1
    -0
      bin/which
  2. +1
    -1
      bin/which.js
  3. +1
    -1
      build_js.hxml
  4. +1
    -1
      build_neko.hxml
  5. +2
    -1
      build_php.hxml
  6. +0
    -1
      haxelib.json
  7. +58
    -0
      lib/php/tink/cli/Doc0.php
  8. +149
    -0
      lib/php/tink/cli/Router0.php
  9. +0
    -17
      lib/php/which/Main.php
  10. +3
    -3
      lib/php/which/Program.php
  11. +30
    -0
      lib/php/which/Version.php
  12. +1
    -1
      src/which/Main.hx
  13. +3
    -1
      src/which/Program.hx
  14. +2
    -0
      src/which/Version.hx
  15. +1
    -3
      tool/clean.ps1
  16. +3
    -3
      tool/dist.ps1

+ 1
- 0
bin/which View File

@@ -3,6 +3,7 @@

use haxe\{EntryPoint};
use php\{Boot};
use which\{Program};

// Load the dependencies.
$autoload = new SplFileInfo(__DIR__."/../../../autoload.php");


+ 1
- 1
bin/which.js
File diff suppressed because it is too large
View File


+ 1
- 1
build_js.hxml View File

@@ -5,7 +5,7 @@ share/build.hxml
--each
--dce full
--js bin/which.js
--main Program
--main which.Program

--next
--js lib/js/which.js

+ 1
- 1
build_neko.hxml View File

@@ -1,4 +1,4 @@
--dce full
--main Program
--main which.Program
--neko run.n
share/build.hxml

+ 2
- 1
build_php.hxml View File

@@ -1,5 +1,6 @@
--dce no
--define php-lib=php
--define real-position
--main Program
--main which.Program
--php lib
share/build.hxml

+ 0
- 1
haxelib.json View File

@@ -4,7 +4,6 @@
"dependencies": {"thenshim": "1.1.0", "tink_cli": "0.5.1"},
"description": "Find the instances of an executable in the system path. Like the `which` Linux command.",
"license": "MIT",
"main": "Program",
"name": "which",
"releasenote": "Initial release.",
"tags": ["cross", "find", "path", "system", "utility", "which"],


+ 58
- 0
lib/php/tink/cli/Doc0.php View File

@@ -0,0 +1,58 @@
<?php
/**
* Generated by Haxe 4.1.1
*/

namespace tink\cli;

use \php\_Boot\HxAnon;
use \php\Boot;

class Doc0 {
/**
* @var object
*/
static public $doc;

/**
* @return object
*/
public static function get () {
if (Doc0::$doc === null) {
Doc0::$doc = new HxAnon([
"doc" => " Find the instances of an executable in the system path. ",
"commands" => \Array_hx::wrap([new HxAnon([
"isDefault" => true,
"isSub" => false,
"names" => new \Array_hx(),
"doc" => " <command> : The name of the command to find. ",
])]),
"flags" => \Array_hx::wrap([
new HxAnon([
"names" => \Array_hx::wrap(["--all"]),
"aliases" => \Array_hx::wrap(["a"]),
"doc" => " List all instances of executables found (instead of just the first one). ",
]),
new HxAnon([
"names" => \Array_hx::wrap(["--help"]),
"aliases" => \Array_hx::wrap(["h"]),
"doc" => " Output usage information. ",
]),
new HxAnon([
"names" => \Array_hx::wrap(["--silent"]),
"aliases" => \Array_hx::wrap(["s"]),
"doc" => " Silence the output, just return the exit code (0 if any executable is found, otherwise 1). ",
]),
new HxAnon([
"names" => \Array_hx::wrap(["--version"]),
"aliases" => \Array_hx::wrap(["v"]),
"doc" => " Output the version number. ",
]),
]),
]);
}
return Doc0::$doc;
}
}

Boot::registerClass(Doc0::class, 'tink.cli.Doc0');

+ 149
- 0
lib/php/tink/cli/Router0.php View File

@@ -0,0 +1,149 @@
<?php
/**
* Generated by Haxe 4.1.1
*/

namespace tink\cli;

use \php\_Boot\HxAnon;
use \tink\core\_Future\SyncFuture;
use \php\Boot;
use \haxe\Exception;
use \tink\core\Noise;
use \tink\core\TypedError;
use \which\Program;
use \tink\core\Outcome;
use \tink\core\_Lazy\LazyConst;
use \php\_Boot\HxString;
use \tink\core\_Future\Future_Impl_;
use \tink\core\_Promise\Promise_Impl_;
use \tink\core\FutureObject;

class Router0 extends Router {
/**
* @param Program $command
* @param Prompt $prompt
*
* @return void
*/
public function __construct ($command, $prompt) {
parent::__construct($command, $prompt, true);
}

/**
* @param \Array_hx $args
*
* @return FutureObject
*/
public function process ($args) {
$_gthis = $this;
if (($args->arr[0] ?? null) === null) {
$args1 = null;
$_g = $this->processArgs($args);
$__hx__switch = ($_g->index);
if ($__hx__switch === 0) {
$args1 = $_g->params[0];
} else if ($__hx__switch === 1) {
return new SyncFuture(new LazyConst(Outcome::Failure($_g->params[0])));
}
return Promise_Impl_::next($this->promptRequired(), function ($_) use (&$args1, &$_gthis) {
return $_gthis->run_run($args1);
});
} else {
$args2 = null;
$_g = $this->processArgs($args);
$__hx__switch = ($_g->index);
if ($__hx__switch === 0) {
$args2 = $_g->params[0];
} else if ($__hx__switch === 1) {
return new SyncFuture(new LazyConst(Outcome::Failure($_g->params[0])));
}
return Promise_Impl_::next($this->promptRequired(), function ($_) use (&$args2, &$_gthis) {
return $_gthis->run_run($args2);
});
}
}

/**
* @param \Array_hx $args
* @param int $index
*
* @return int
*/
public function processAlias ($args, $index) {
$str = ($args->arr[$index] ?? null);
$_g = 1;
$_g1 = mb_strlen($str);
while ($_g < $_g1) {
$i = $_g++;
$_g2 = HxString::charCodeAt($str, $i);
if ($_g2 === null) {
throw Exception::thrown("Invalid alias '-" . ((($i < 0 ? "" : mb_substr($str, $i, 1)))??'null') . "'");
} else {
if ($_g2 === 97) {
$this->command->all = true;
} else if ($_g2 === 104) {
$this->command->help = true;
} else if ($_g2 === 115) {
$this->command->silent = true;
} else if ($_g2 === 118) {
$this->command->version = true;
} else {
throw Exception::thrown("Invalid alias '-" . ((($i < 0 ? "" : mb_substr($str, $i, 1)))??'null') . "'");
}
}
}
return $index - $index;
}

/**
* @param \Array_hx $args
* @param int $index
*
* @return int
*/
public function processFlag ($args, $index) {
$__hx__switch = (($args->arr[$index] ?? null));
if ($__hx__switch === "--all") {
$this->command->all = true;
} else if ($__hx__switch === "--help") {
$this->command->help = true;
} else if ($__hx__switch === "--silent") {
$this->command->silent = true;
} else if ($__hx__switch === "--version") {
$this->command->version = true;
} else {
return -1;
}
return $index - $index;
}

/**
* @return FutureObject
*/
public function promptRequired () {
return Future_Impl_::async(function ($cb) {
$cb(Outcome::Success(Noise::Noise()));
});
}

/**
* @param \Array_hx $args
*
* @return FutureObject
*/
public function run_run ($args) {
if ($args->length < 0) {
return new SyncFuture(new LazyConst(Outcome::Failure(new TypedError(null, "Insufficient arguments. Expected: " . 0 . ", Got: " . ($args->length??'null'), new HxAnon([
"fileName" => "src/which/Program.hx",
"lineNumber" => 34,
"className" => "tink.cli.Router0",
"methodName" => "run_run",
])))));
}
$this->command->run($args->slice(0, $args->length));
return new SyncFuture(new LazyConst(Outcome::Success(Noise::Noise())));
}
}

Boot::registerClass(Router0::class, 'tink.cli.Router0');

+ 0
- 17
lib/php/which/Main.php View File

@@ -5,7 +5,6 @@

namespace which;

use \php\_Boot\HxAnon;
use \php\Boot;
use \thenshim\_Promise\Promise_Impl_;
use \thenshim\Thenable;
@@ -14,7 +13,6 @@ use \thenshim\Thenable;
* The main class.
*/
class Main {

/**
* Finds the first instance of the specified `command` in the system path.
*
@@ -41,21 +39,6 @@ class Main {
}
});
}

/**
* @internal
* @access private
*/
static public function __hx__init ()
{
static $called = false;
if ($called) return;
$called = true;


}
}

Boot::registerClass(Main::class, 'which.Main');
Boot::registerMeta(Main::class, new HxAnon(["obj" => new HxAnon(["expose" => null])]));
Main::__hx__init();

lib/php/Program.php → lib/php/which/Program.php View File

@@ -3,13 +3,13 @@
* Generated by Haxe 4.1.1
*/

namespace which;

use \tink\Cli;
use \which\Main;
use \thenshim\PromiseTools;
use \php\Boot;
use \tink\cli\prompt\RetryPrompt;
use \tink\cli\Doc0;
use \which\FinderException;
use \tink\cli\doc\DefaultFormatter;
use \tink\cli\Router0;
use \thenshim\_Promise\Promise_Impl_;
@@ -96,4 +96,4 @@ class Program {
}
}

Boot::registerClass(Program::class, 'Program');
Boot::registerClass(Program::class, 'which.Program');

+ 30
- 0
lib/php/which/Version.php View File

@@ -0,0 +1,30 @@
<?php
/**
* Generated by Haxe 4.1.1
*/

namespace which;

use \php\Boot;
use \sys\io\File;
use \haxe\Json;

/**
* Provides the version number of this package.
*/
class Version {
/**
* Reads the version number of this package from the `haxelib.json` file.
*
* @return string
*/
public static function getHaxelibVersion () {
try {
return Boot::dynamicField(Json::phpJsonDecode(File::getContent("haxelib.json")), 'version');
} catch(\Throwable $_g) {
return "0.0.0";
}
}
}

Boot::registerClass(Version::class, 'which.Version');

+ 1
- 1
src/which/Main.hx View File

@@ -8,7 +8,7 @@ import php.NativeStructArray;
#end

/** The main class. **/
@expose class Main {
@:expose class Main {

/** Finds the first instance of the specified `command` in the system path. **/
public static function which(command: String, ?options: #if php NativeStructArray<WhichOptions> #else WhichOptions #end): Promise<Dynamic> {


src/Program.hx → src/which/Program.hx View File

@@ -1,3 +1,5 @@
package which;

import tink.Cli;
import tink.cli.Rest;
import which.FinderException;
@@ -6,7 +8,7 @@ import which.Main;
using thenshim.PromiseTools;

/** Find the instances of an executable in the system path. **/
@:expose class Program {
class Program {

/** List all instances of executables found (instead of just the first one). **/
public var all: Bool = false;

src/Version.hx → src/which/Version.hx View File

@@ -1,3 +1,5 @@
package which;

import haxe.Json;
import haxe.macro.Expr.ExprOf;
import sys.io.File;

+ 1
- 3
tool/clean.ps1 View File

@@ -6,6 +6,4 @@ foreach ($item in ".temp", "doc/api", "lib/index.php", "lib/js/which.*", "lib/ph
if (Test-Path $item) { Remove-Item $item -Force -Recurse }
}

foreach ($item in Get-ChildItem var -Exclude .gitkeep) {
Remove-Item $item -Recurse
}
Get-ChildItem var -Exclude .gitkeep | Remove-Item -Recurse

+ 3
- 3
tool/dist.ps1 View File

@@ -11,6 +11,6 @@ node_modules/.bin/ncc build bin/which.js --minify --out=var
if (-not $IsWindows) { chmod +x bin/which.js }

Remove-Item lib/index.php
foreach ($item in Get-ChildItem lib/php) {
if (-not ("Program.php", "which" -contains $item.Name)) { Remove-Item $item -Recurse }
}
Get-ChildItem lib/php -Exclude tink, which | Remove-Item -Recurse
Get-ChildItem lib/php/tink -Exclude cli | Remove-Item -Recurse
Get-ChildItem lib/php/tink/cli -Exclude *0.php | Remove-Item -Recurse

Loading…
Cancel
Save