5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup Maintenance
24 use \Cdb\Exception
as CdbException
;
25 use \Cdb\Reader
as CdbReader
;
28 require_once __DIR__
. '/commandLine.inc';
30 function cdbShowHelp( $command ) {
32 'load' => 'load a cdb file for reading',
33 'get' => 'get a value for a key',
36 'help' => 'help about a command',
39 $command = 'fullhelp';
41 if ( $command === 'fullhelp' ) {
42 $max_cmd_len = max( array_map( 'strlen', array_keys( $commandList ) ) );
43 foreach ( $commandList as $cmd => $desc ) {
44 printf( "%-{$max_cmd_len}s: %s\n", $cmd, $desc );
46 } elseif ( isset( $commandList[$command] ) ) {
47 print "$command: $commandList[$command]\n";
49 print "$command: command does not exist or no help for it\n";
57 static $fileHandle = false;
59 $line = Maintenance
::readconsole();
60 if ( $line === false ) {
64 $args = explode( ' ', $line, 2 );
65 $command = array_shift( $args );
70 // show an help message
71 cdbShowHelp( array_shift( $args ) );
74 if ( !isset( $args[0] ) ) {
75 print "Need a filename there buddy\n";
79 print "Loading cdb file $file...";
81 $fileHandle = CdbReader
::open( $file );
82 } catch ( CdbException
$e ) {
86 print "not a cdb file or unable to read it\n";
93 print "Need to load a cdb file first\n";
96 if ( !isset( $args[0] ) ) {
97 print "Need to specify a key, Luke\n";
101 $res = $fileHandle->get( $args[0] );
102 } catch ( CdbException
$e ) {
103 print "Unable to read key from file\n";
106 if ( $res === false ) {
107 print "No such key/value pair\n";
108 } elseif ( is_string( $res ) ) {
125 print "Bad command\n";
128 if ( function_exists( 'readline_add_history' ) ) {
129 readline_add_history( $line );