179179 case '--version ' :
180180 case '-V ' :
181181 case '-v ' :
182- displayVersion ();
182+ display_version ();
183183
184184 exit ;
185185 case '--help ' :
186186 case '-H ' :
187187 case '-h ' :
188- displayHelp ();
188+ display_help ();
189189
190190 exit ;
191191
192192 default :
193193 echoQuiet ("ERROR: Invalid Argument: ( $ arg) \n\n" . PHP_EOL . PHP_EOL );
194- displayHelp ();
194+ display_help ();
195195
196196 exit (1 );
197197 }
215215 }
216216 }
217217} else {
218- displayHelp ();
218+ display_help ();
219219
220220 exit (0 );
221221}
@@ -437,7 +437,11 @@ function geocodeAddress(string $siteAddr1, string $siteAddr2, string $siteCity,
437437
438438 if (!$ geocodeApiKey ) {
439439 // Dont even try without the key
440- displayHelp ('Error: --geocode-api-key must be given with --geocode-address ' );
440+ print 'Error: --geocode-api-key must be given with --geocode-address ' . PHP_EOL ;
441+
442+ display_help ();
443+
444+ exit (1 );
441445 }
442446
443447 $ requestUrl = sprintf ('%s?address=%s,%s,%s,%s&key=%s ' , $ googleApiUrl , urlencode ($ siteAddr1 ), urlencode ($ siteAddr2 ), urlencode ($ siteCity ), urlencode ($ siteCountry ), $ geocodeApiKey );
@@ -511,12 +515,16 @@ function fetchCurl(string $url) : string|false {
511515 global $ verbose , $ debug , $ httpsProxy ;
512516
513517 if (!function_exists ('curl_init ' )) {
514- displayHelp ('Error: cURL must be enabled in PHP if --geocode is specified. ' . PHP_EOL . 'See http://php.net/manual/en/curl.setup.php for help. ' . PHP_EOL );
518+ print 'Error: cURL must be enabled in PHP if --geocode is specified. ' . PHP_EOL . 'See http://php.net/manual/en/curl.setup.php for help. ' . PHP_EOL ;
519+
520+ display_help ();
521+
522+ exit (1 );
515523 }
516524
517- $ curl = curl_init ();
518- $ header [ 0 ] = ' Accept: text/xml,application/xml,application/json,application/xhtml+xml, ' ;
519- $ header [0 ] . = 'text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 ' ;
525+ $ curl = curl_init ();
526+
527+ $ header [] = 'Accept: text/xml,application/xml,application/json,application/xhtml+xml, text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 ' ;
520528 $ header [] = 'Cache-Control: max-age=0 ' ;
521529 $ header [] = 'Connection: keep-alive ' ;
522530 $ header [] = 'Keep-Alive: 300 ' ;
@@ -535,13 +543,15 @@ function fetchCurl(string $url) : string|false {
535543 if ($ verbose || $ debug ) {
536544 echoQuiet ("Using HTTPS proxy: $ httpsProxy " . PHP_EOL );
537545 }
546+
538547 curl_setopt ($ curl , CURLOPT_PROXY , $ httpsProxy );
539548 }
540549
541550 $ buffer = curl_exec ($ curl );
542551
543552 if ($ buffer === false ) {
544553 $ error = curl_error ($ curl );
554+
545555 echoQuiet ('Error: cURL request failed: ' . $ error . PHP_EOL );
546556
547557 return false ;
@@ -551,11 +561,11 @@ function fetchCurl(string $url) : string|false {
551561}
552562
553563/**
554- * displayVersion - displays version information
564+ * display_version - displays version information
555565 *
556566 * @return void
557567 */
558- function displayVersion () : void {
568+ function display_version () : void {
559569 $ version = get_cacti_cli_version ();
560570 echoQuiet ("Cacti Add Site Utility, Version $ version, " . COPYRIGHT_YEARS . PHP_EOL );
561571}
@@ -565,14 +575,10 @@ function displayVersion() : void {
565575 *
566576 * @return void
567577 */
568- function displayHelp ( mixed $ errorMessage = null ) : void {
578+ function display_help ( ) : void {
569579 global $ log ;
570580 $ log = false ;
571- displayVersion ();
572-
573- if ($ errorMessage ) {
574- echoQuiet ("$ errorMessage " . PHP_EOL . PHP_EOL );
575- }
581+ display_version ();
576582
577583 echoQuiet (PHP_EOL );
578584 echoQuiet ('Usage: add_site.php [site-options] [--quiet] ' . PHP_EOL . PHP_EOL );
0 commit comments