]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/commandline.inc
4a7757fb98f13e43c47bf55cdd0841da848304fd
[quix0rs-gnu-social.git] / scripts / commandline.inc
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, Control Yourself, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 // -*- mode: php -*-
21
22 # Abort if called from a web server
23
24 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
25     print "This script must be run from the command line\n";
26     exit();
27 }
28
29 define('LACONICA', true);
30
31 // Set various flags so we don't time out on long-running processes
32
33 ini_set("max_execution_time", "0");
34 ini_set("max_input_time", "0");
35 set_time_limit(0);
36 mb_internal_encoding('UTF-8');
37
38 // Add extlib to our path so we can get Console_Getopt
39
40 $_extra_path = array(INSTALLDIR.'/extlib/');
41
42 set_include_path(implode(PATH_SEPARATOR, $_extra_path) . PATH_SEPARATOR . get_include_path());
43
44 require_once 'Console/Getopt.php';
45
46 // Note: $shortoptions and $longoptions should be pre-defined!
47
48 $_default_shortoptions = 'qvhc:s:p:';
49
50 $_default_longoptions = array('quiet', 'verbose', 'help', 'conf=', 'server=', 'path=');
51
52 if (isset($shortoptions)) {
53     $shortoptions .= $_default_shortoptions;
54 } else {
55     $shortoptions = $_default_shortoptions;
56 }
57
58 if (isset($longoptions)) {
59     $longoptions = array_merge($longoptions, $_default_longoptions);
60 } else {
61     $longoptions = $_default_longoptions;
62 }
63
64 $parser = new Console_Getopt();
65
66 list($options, $args) = $parser->getopt($argv, $shortoptions, $longoptions);
67
68 function show_help()
69 {
70     global $helptext;
71
72     $_default_help_text = <<<END_OF_DEFAULT
73 General options:
74
75     -q --quiet           Quiet (little output)
76     -v --verbose         Verbose (lots of output)
77     -c --conf=<filename> Use <filename> as config file
78     -s --server=<name>   Use <name> as server name
79     -p --path=<path>     Use <path> as path name
80     -h --help            Show this message and quit.
81
82 END_OF_DEFAULT;
83         if (isset($helptext)) {
84             print $helptext;
85         }
86         print $_default_help_text;
87         exit(0);
88 }
89
90 foreach ($options as $option) {
91
92     switch ($option[0]) {
93      case '--server':
94      case 's':
95         $server = $option[1];
96         break;
97
98      case '--path':
99      case 'p':
100         $path = $option[1];
101         break;
102
103      case '--conf':
104      case 'c':
105         $conffile = $option[1];
106         break;
107
108      case '--help':
109      case 'h':
110         show_help();
111     }
112 }
113
114 require_once INSTALLDIR . '/lib/common.php';
115
116 set_error_handler('common_error_handler');
117
118 function have_option($str)
119 {
120    global $options;
121    foreach ($options as $option) {
122        if ($option[0] == $str) {
123           return true;
124        }
125    }
126    return false;
127 }
128
129 function get_option_value($str)
130 {
131    global $options;
132    foreach ($options as $option) {
133        if ($option[0] == $str) {
134           return $option[1];
135        }
136    }
137    return null;
138 }