listStacks method

Future<List<AutomationStackSummary>> listStacks({
  1. bool all = false,
})

Returns stack summaries from pulumi stack ls --json.

Implementation

Future<List<AutomationStackSummary>> listStacks({bool all = false}) async {
  final args = <String>['stack', 'ls', '--json'];
  if (all) {
    args.add('--all');
  }

  final result = await runPulumiCommand(args);
  final decoded = jsonDecode(result.stdout);
  if (decoded is! List) {
    throw FormatException(
      'Expected array JSON from `pulumi stack ls --json`',
    );
  }

  return decoded
      .whereType<Map>()
      .map((entry) {
        final mapped = entry.map((key, value) => MapEntry('$key', value));
        return AutomationStackSummary(
          name: '${mapped['name'] ?? ''}',
          current: mapped['current'] == true,
          raw: mapped,
        );
      })
      .toList(growable: false);
}