kubensSpec top-level property

FigSpec kubensSpec
final

Implementation

final FigSpec kubensSpec = FigSpec(
  name: 'kubens',
  description: 'Switch between Kubernetes-namespaces',
  additionalSuggestions: [
    FigSuggestion(
      name: '-',
      priority: 85,
      description: 'Switch to previous namespace within the current context',
      icon: 'fig://icon?type=asterisk',
    ),
  ],
  parserDirectives: ParserDirectives(
    flagsArePosixNoncompliant: true,
  ),
  options: [
    FigOption(
      name: ['--help', '-h'],
      description: 'Show help for kubens',
    ),
    FigOption(
      name: ['--current', '-c'],
      description: 'Show current namespace',
    ),
  ],
  args: [
    FigArg(
      name: 'namespace',
      generators: [
        FigGenerator(
          script: ['bash', '-c', 'kubens | grep -v \$(kubens -c)'],
          postProcess: (String out, [List<String>? tokens]) {
            return out
                .split('\n')
                .map(
                  (item) => FigSuggestion(
                    name: item,
                    priority: 90,
                    icon: 'fig://icon?type=kubernetes',
                  ),
                )
                .toList();
          },
        ),
        FigGenerator(
          script: ['kubens', '-c'],
          postProcess: (String out, [List<String>? tokens]) {
            if (out.isEmpty) return [];
            return [
              FigSuggestion(
                name: out,
                priority: 100,
                icon: '⭐️',
              ),
            ];
          },
        ),
      ],
      isOptional: true,
    ),
  ],
);