targetGenerator function
Implementation
FigGenerator targetGenerator({String? kind}) {
return FigGenerator(
custom: (tokens, executeShellCommand, context) async {
if (executeShellCommand == null) return [];
final output = await executeShellCommand(ExecuteCommandInput(
command: 'cargo',
args: ['metadata', '--format-version', '1', '--no-deps'],
));
final manifest = Metadata.fromJson(jsonDecode(output.stdout));
final packages = rootPackageOrLocal(manifest);
var targets = packages.expand((pkg) => pkg.targets).toList();
if (kind != null) {
targets =
targets.where((target) => target.kind.contains(kind)).toList();
}
return targets.map((target) {
final path = context != null
? target.srcPath.replaceFirst(context.currentWorkingDirectory, '')
: target.srcPath;
return FigSuggestion(
icon: '🎯',
name: target.name,
description: path,
);
}).toList();
},
);
}