dockerGenerators top-level property
Docker/Podman 生成器集合
Implementation
final Map<String, FigGenerator> dockerGenerators = {
'runningDockerContainers': FigGenerator(
script: ['podman', 'ps', '--format', '{{ json . }}'],
postProcess: postProcessDockerPs,
),
'allDockerContainers': FigGenerator(
script: ['podman', 'ps', '-a', '--format', '{{ json . }}'],
postProcess: postProcessDockerPs,
),
'pausedDockerContainers': FigGenerator(
script: [
'podman',
'ps',
'--filter',
'status=paused',
'--format',
'{{ json . }}'
],
postProcess: postProcessDockerPs,
),
'allLocalImages': FigGenerator(
script: ['podman', 'image', 'ls', '--format', '{{ json . }}'],
postProcess: (String out, [List<String>? tokens]) {
return out
.split('\n')
.where((line) => line.trim().isNotEmpty)
.map<FigSuggestion?>((line) {
try {
final data = json.decode(line) as Map<String, dynamic>;
final id = data['Id']?.toString() ?? '';
final repository = data['repository']?.toString() ?? '';
if (id.isEmpty) return null;
return FigSuggestion(
name: id,
displayName:
'$repository - ${id.length > 12 ? '${id.substring(0, 12)}...' : id}',
icon: 'fig://icon?type=docker',
);
} catch (error) {
print('Error parsing Docker image: $error');
return null;
}
})
.where((suggestion) => suggestion != null)
.cast<FigSuggestion>()
.toList();
},
),
'allLocalImagesWithRepository': FigGenerator(
script: ['podman', 'image', 'ls', '--format', '{{ json . }}'],
postProcess: (String out, [List<String>? tokens]) {
return out
.split('\n')
.where((line) => line.trim().isNotEmpty)
.map<FigSuggestion?>((line) {
try {
final data = json.decode(line) as Map<String, dynamic>;
final repository = data['repository']?.toString() ?? '';
final id = data['Id']?.toString() ?? '';
if (repository.isEmpty) return null;
return FigSuggestion(
name: repository,
displayName:
'$repository - ${id.length > 12 ? '${id.substring(0, 12)}...' : id}',
icon: 'fig://icon?type=docker',
);
} catch (error) {
print('Error parsing Docker image with repository: $error');
return null;
}
})
.where((suggestion) => suggestion != null)
.cast<FigSuggestion>()
.toList();
},
),
'dockerHubSearch': FigGenerator(
script: (List<String> context) {
if (context.isEmpty || context.last.isEmpty) return null;
final searchTerm = context.last;
return ['podman', 'search', searchTerm, '--format', '{{ json . }}'];
},
postProcess: (String out, [List<String>? tokens]) {
return out
.split('\n')
.where((line) => line.trim().isNotEmpty)
.map<FigSuggestion?>((line) {
try {
final data = json.decode(line) as Map<String, dynamic>;
final name = data['Name']?.toString() ?? '';
if (name.isEmpty) return null;
return FigSuggestion(
name: name,
icon: 'fig://icon?type=docker',
);
} catch (error) {
print('Error parsing Docker Hub search result: $error');
return null;
}
})
.where((suggestion) => suggestion != null)
.cast<FigSuggestion>()
.toList();
},
trigger: (String newToken, String oldToken) => true,
),
'listDockerNetworks': FigGenerator(
script: ['podman', 'network', 'list', '--format', '{{ json . }}'],
postProcess: sharedPostProcess,
),
'listDockerSecrets': FigGenerator(
script: ['podman', 'secret', 'list', '--format', '{{ json . }}'],
postProcess: sharedPostProcess,
),
'listDockerVolumes': FigGenerator(
script: ['podman', 'volume', 'list', '--format', '{{ json . }}'],
postProcess: (String out, [List<String>? tokens]) {
return out
.split('\n')
.where((line) => line.trim().isNotEmpty)
.map<FigSuggestion?>((line) {
try {
final data = json.decode(line) as Map<String, dynamic>;
final name = data['Name']?.toString() ?? '';
if (name.isEmpty) return null;
return FigSuggestion(
name: name,
icon: 'fig://icon?type=docker',
);
} catch (error) {
print('Error parsing Docker volume: $error');
return null;
}
})
.where((suggestion) => suggestion != null)
.cast<FigSuggestion>()
.toList();
},
),
};