X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=bin%2Fcli.class.php;h=5340869a1cae97b5884b674c25b97c59cc3648fa;hb=7a7971bd6efc4c713933abb705d165bb677344b3;hp=36f519d63e9179836baa317e1026d3f5cb23899b;hpb=776ff7a00ca98cd3f668e43e4419c62791b1110f;p=civicrm-core.git diff --git a/bin/cli.class.php b/bin/cli.class.php index 36f519d63e..5340869a1c 100644 --- a/bin/cli.class.php +++ b/bin/cli.class.php @@ -1,14 +1,14 @@ _entity, $this->_action, $this->_params); } - if ($result['is_error'] != 0) { + if (!empty($result['is_error'])) { $this->_log($result['error_message']); return FALSE; } + elseif ($this->_output === 'json') { + echo json_encode($result, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0); + } elseif ($this->_output) { print_r($result['values']); } @@ -175,6 +179,9 @@ class civicrm_cli { elseif ($arg == '-o' || $arg == '--output') { $this->_output = TRUE; } + elseif ($arg == '-J' || $arg == '--json') { + $this->_output = 'json'; + } elseif ($arg == '-j' || $arg == '--joblog') { $this->_joblog = TRUE; } @@ -215,7 +222,12 @@ class civicrm_cli { $civicrm_root = dirname(__DIR__); chdir($civicrm_root); - require_once 'civicrm.config.php'; + if (getenv('CIVICRM_SETTINGS')) { + require_once getenv('CIVICRM_SETTINGS'); + } + else { + require_once 'civicrm.config.php'; + } // autoload if (!class_exists('CRM_Core_ClassLoader')) { require_once $civicrm_root . '/CRM/Core/ClassLoader.php'; @@ -294,12 +306,13 @@ class civicrm_cli { * @return string */ private function _getUsage() { - $out = "Usage: cli.php -e entity -a action [-u user] [-s site] [--output] [PARAMS]\n"; + $out = "Usage: cli.php -e entity -a action [-u user] [-s site] [--output|--json] [PARAMS]\n"; $out .= " entity is the name of the entity, e.g. Contact, Event, etc.\n"; $out .= " action is the name of the action e.g. Get, Create, etc.\n"; $out .= " user is an optional username to run the script as\n"; $out .= " site is the domain name of the web site (for Drupal multi site installs)\n"; - $out .= " --output will print the result from the api call\n"; + $out .= " --output will pretty print the result from the api call\n"; + $out .= " --json will print the result from the api call as JSON\n"; $out .= " PARAMS is one or more --param=value combinations to pass to the api\n"; return ts($out); }