Version 1
[yaffs-website] / vendor / drush / drush / commands / core / outputformat / string.inc
diff --git a/vendor/drush/drush/commands/core/outputformat/string.inc b/vendor/drush/drush/commands/core/outputformat/string.inc
new file mode 100644 (file)
index 0000000..a86e7d1
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * Output formatter 'string'
+ *
+ * @param $data
+ *   The render data may be either a string or an array
+ *   string - printed as-is, without quotes
+ *   array - the value of the first item in the array is printed as-is
+ * @param $metadata
+ *   'label' - If present, prints "label: " prior to the data
+ *
+ * Code:
+ *
+ *   return DRUSH_VERSION;
+ *
+ * Output with --format=string:
+ *
+ *   6.0-dev
+ */
+class drush_outputformat_string extends drush_outputformat {
+  function format($data, $metadata) {
+    // If the data is an array, print the value of the first item.
+    if (is_array($data)) {
+      if (count($data) > 1) {
+        return $this->format_error("Multiple rows provided where only one is allowed.");
+      }
+      if (!empty($data)) {
+        $data = reset($data);
+      }
+      if (is_array($data)) {
+        return $this->format_error("Array provided where a string is required.");
+      }
+    }
+    return (string)$data;
+  }
+}