php/WP_CLI/SynopsisParser.php
public static function render( &$synopsis ) {
		if ( ! is_array( $synopsis ) ) {
			return '';
		}
		$bits               = [
			'positional' => '',
			'assoc'      => '',
			'generic'    => '',
			'flag'       => '',
		];
		$reordered_synopsis = [
			'positional' => [],
			'assoc'      => [],
			'generic'    => [],
			'flag'       => [],
		];
		foreach ( $bits as $key => &$value ) {
			foreach ( $synopsis as $arg ) {
				if ( empty( $arg['type'] )
					|| $key !== $arg['type'] ) {
					continue;
				}

				if ( empty( $arg['name'] ) && 'generic' !== $arg['type'] ) {
					continue;
				}

				if ( 'positional' === $key ) {
					$rendered_arg = "<{$arg['name']}>";

					$reordered_synopsis['positional'] [] = $arg;
				} elseif ( 'assoc' === $key ) {
					$arg_value    = isset( $arg['value']['name'] ) ? $arg['value']['name'] : $arg['name'];
					$rendered_arg = "--{$arg['name']}=<{$arg_value}>";

					$reordered_synopsis['assoc'] [] = $arg;
				} elseif ( 'generic' === $key ) {
					$rendered_arg = '--<field>=<value>';

					$reordered_synopsis['generic'] [] = $arg;
				} elseif ( 'flag' === $key ) {
					$rendered_arg = "--{$arg['name']}";

					$reordered_synopsis['flag'] [] = $arg;
				}
				if ( ! empty( $arg['repeating'] ) ) {
					$rendered_arg = "{$rendered_arg}...";
				}
				if ( ! empty( $arg['optional'] ) ) {
					$rendered_arg = "[{$rendered_arg}]";
				}
				$value .= "{$rendered_arg} ";
			}
		}
		$rendered = '';
		foreach ( $bits as $v ) {
			if ( ! empty( $v ) ) {
				$rendered .= $v;
			}
		}

		$synopsis = array_merge(
			$reordered_synopsis['positional'],
			$reordered_synopsis['assoc'],
			$reordered_synopsis['generic'],
			$reordered_synopsis['flag']
		);

		return rtrim( $rendered, ' ' );
	}
public static function render( &$synopsis ) {
		if ( ! is_array( $synopsis ) ) {
			return '';
		}
		$bits               = [
			'positional' => '',
			'assoc'      => '',
			'generic'    => '',
			'flag'       => '',
		];
		$reordered_synopsis = [
			'positional' => [],
			'assoc'      => [],
			'generic'    => [],
			'flag'       => [],
		];
		foreach ( $bits as $key => &$value ) {
			foreach ( $synopsis as $arg ) {
				if ( empty( $arg['type'] )
					|| $key !== $arg['type'] ) {
					continue;
				}

				if ( empty( $arg['name'] ) && 'generic' !== $arg['type'] ) {
					continue;
				}

				if ( 'positional' === $key ) {
					$rendered_arg = "<{$arg['name']}>";

					$reordered_synopsis['positional'] [] = $arg;
				} elseif ( 'assoc' === $key ) {
					$arg_value    = isset( $arg['value']['name'] ) ? $arg['value']['name'] : $arg['name'];
					$rendered_arg = "--{$arg['name']}=<{$arg_value}>";

					$reordered_synopsis['assoc'] [] = $arg;
				} elseif ( 'generic' === $key ) {
					$rendered_arg = '--<field>=<value>';

					$reordered_synopsis['generic'] [] = $arg;
				} elseif ( 'flag' === $key ) {
					$rendered_arg = "--{$arg['name']}";

					$reordered_synopsis['flag'] [] = $arg;
				}
				if ( ! empty( $arg['repeating'] ) ) {
					$rendered_arg = "{$rendered_arg}...";
				}
				if ( ! empty( $arg['optional'] ) ) {
					$rendered_arg = "[{$rendered_arg}]";
				}
				$value .= "{$rendered_arg} ";
			}
		}
		$rendered = '';
		foreach ( $bits as $v ) {
			if ( ! empty( $v ) ) {
				$rendered .= $v;
			}
		}

		$synopsis = array_merge(
			$reordered_synopsis['positional'],
			$reordered_synopsis['assoc'],
			$reordered_synopsis['generic'],
			$reordered_synopsis['flag']
		);

		return rtrim( $rendered, ' ' );
	}
public static function render ( & $ synopsis ) { if ( ! is_array ( $ synopsis ) ) { return '' ; } $ bits = [ 'positional' => '' , 'assoc' => '' , 'generic' => '' , 'flag' => '' , ] ; $ reordered_synopsis = [ 'positional' => [ ] , 'assoc' => [ ] , 'generic' => [ ] , 'flag' => [ ] , ] ; foreach ( $ bits as $ key => & $ value ) { foreach ( $ synopsis as $ arg ) { if ( empty ( $ arg [ 'type' ] ) || $ key !== $ arg [ 'type' ] ) { continue ; } if ( empty ( $ arg [ 'name' ] ) && 'generic' !== $ arg [ 'type' ] ) { continue ; } if ( 'positional' === $ key ) { $ rendered_arg = "<{$arg['name']}>" ; $ reordered_synopsis [ 'positional' ] [ ] = $ arg ; } elseif ( 'assoc' === $ key ) { $ arg_value = isset ( $ arg [ 'value' ] [ 'name' ] ) ? $ arg [ 'value' ] [ 'name' ] : $ arg [ 'name' ] ; $ rendered_arg = "--{$arg['name']}=<{$arg_value}>" ; $ reordered_synopsis [ 'assoc' ] [ ] = $ arg ; } elseif ( 'generic' === $ key ) { $ rendered_arg = '--<field>=<value>' ; $ reordered_synopsis [ 'generic' ] [ ] = $ arg ; } elseif ( 'flag' === $ key ) { $ rendered_arg = "--{$arg['name']}" ; $ reordered_synopsis [ 'flag' ] [ ] = $ arg ; } if ( ! empty ( $ arg [ 'repeating' ] ) ) { $ rendered_arg = "{$rendered_arg}..." ; } if ( ! empty ( $ arg [ 'optional' ] ) ) { $ rendered_arg = "[{$rendered_arg}]" ; } $ value .= "{$rendered_arg} " ; } } $ rendered = '' ; foreach ( $ bits as $ v ) { if ( ! empty ( $ v ) ) { $ rendered .= $ v ; } } $ synopsis = array_merge ( $ reordered_synopsis [ 'positional' ] , $ reordered_synopsis [ 'assoc' ] , $ reordered_synopsis [ 'generic' ] , $ reordered_synopsis [ 'flag' ] ) ; return rtrim ( $ rendered , ' ' ) ; }
Render the Synopsis into a format string.

@param array $synopsis A structured synopsis. This might get reordered
to match the parsed output.
@return string Rendered synopsis.
Render the Synopsis into a format string .