#!/usr/bin/env php
<?php
$own_autoloader = __DIR__.'/../vendor/autoload.php';
// project/vendor/taeluf/user/bin/tlfuser
$parent_autoloader = __DIR__.'/../../../autoload.php';
if (file_exists($own_autoloader))require_once($own_autoloader);
else if (file_exists($parent_autoloader))require_once($parent_autoloader);
$cli = new \Tlf\Cli();
$cli->load_stdin();
$dir = getcwd();
if ($cli->load_json_file("$dir/.env/config.json")){}
else if ($cli->load_json_file("$dir/.env/env.json")){}
else if ($cli->load_json_file("$dir/.config/env.json")){}
else if ($cli->load_json_file("$dir/.env.json")){}
else if ($cli->load_json_file("$dir/env.json")){}
/**
* Initialize the database
*/
$cli->load_command('init',
function($cli, $args){
list('db'=>$db, 'user'=>$user, 'password'=>$password) = $args;
$pdo = new \PDO('mysql:dbname='.$db,$user,$password);
$lib = new \Tlf\User\Lib($pdo);
$lib->init_db();
},
"Initialize the database. pass args db, user, and password"
);
/**
* Build the user lib, compiling sql.
* This is for use in development, not for use by the user of this lib
*/
$cli->load_command('build',
function($cli, $args){
$ls = new \Tlf\LilSql();
$ls->load_files(__DIR__.'/../code/db/');
$ls->serialize(__DIR__.'/../code/db/serialized.txt');
},
"Build the user lib, compiling sql. This is for development of THIS lib, not for USERS of this lib."
);
$cli->execute();