toText method

String toText({
  1. String indent = '',
  2. bool docs = true,
})

The shape as an indented tree.

A tree rather than a table because results nest, and the thing a reader is looking for — did this field become optional, did that list gain a member — is one line either way. Rendered here rather than in each surface so fw ... --help and docs/capabilities.md cannot describe the same shape differently.

Implementation

String toText({String indent = '', bool docs = true}) {
  var buffer = StringBuffer();
  for (var field in fields) {
    buffer.writeln(
      '$indent${field.name}: ${field.type}${field.optional ? '?' : ''}'
      '${docs && field.doc != null ? '   # ${field.doc}' : ''}',
    );
    if (field.shape case var nested?) {
      buffer.write(nested.toText(indent: '$indent  ', docs: docs));
    }
  }
  return buffer.toString();
}