tlf-cli
#!/usr/bin/env php
<?php
/**
* This cli is used to setup bin scripts
*
* @usage vendor/bin/tlf-cli help
* @usage vendor/bin/tlf-cli setup
*
*/
$own_autloader = dirname(__DIR__).'/vendor/autoload.php';
$their_autoloader = dirname(__DIR__, 3).'/autoload.php'; // presuming vendor/taeluf/cli/bin
//$pwd_autoloader = getcwd().'/vendor/autoload.php';
//if (file_exists($pwd_autoloader))require_once($pwd_autoloader); else
if (file_exists($their_autoloader))require_once($their_autoloader);
else if (file_exists($own_autloader))require_once($own_autloader);
else {
echo "\nautoload file not found.\n";
return;
}
$cli = new \Tlf\Cli();
// load_json_file fails silently if the file does not exist
//$cli->load_json_file(__DIR__.'/defaults.json');
//$cli->load_inputs(json_decode(file_get_contents(__DIR__.'/user_configs.json'),true));
$cli->load_stdin();
$cli->load_command('main',
function($cli, $args){
$cli->call_command('help',[]);
}, 'Show this help menu'
);
$cli->load_command('setup',
function($cli, $args){
$script_name = $cli->prompt("Enter script name");
$file = getcwd().'/bin/'.$script_name;
$write_file = false;
if (file_exists($file)){
$write_file = $cli->ask("Overwrite existing file");
} else {
$write_file = $cli->ask("Create script '$file'");
}
if ($write_file)file_put_contents($file, file_get_contents(__FILE__));
else return;
if ($cli->ask("Make file executable")){
$current_permissions = fileperms($file);
$new_permissions = $current_permissions | 0b001001001;
chmod($file, $new_permissions);
//echo "File permissions are now"
}
}, "Initialize a bin script with Tlf\Cli already setup"
);
$cli->execute();