protected final void run(
        final File exportFile, final Function<KeyPair, String> outputFunction) {
      checkNotNull(parentCommand);
      final BesuCommand besuCommand = parentCommand.parentCommand;
      checkNotNull(besuCommand);

      final File nodePrivateKeyFile = nodePrivateKeyFileOption.getNodePrivateKeyFile();
      if (nodePrivateKeyFile != null && !nodePrivateKeyFile.exists()) {
        throw new CommandLine.ParameterException(
            spec.commandLine(), "Private key file doesn't exist");
      }

      final KeyPair keyPair;
      try {
        keyPair = besuCommand.loadKeyPair(nodePrivateKeyFileOption.getNodePrivateKeyFile());
      } catch (IllegalArgumentException e) {
        throw new CommandLine.ParameterException(
            spec.commandLine(), "Private key cannot be loaded from file", e);
      }
      final String output = outputFunction.apply(keyPair);
      if (exportFile != null) {
        final Path path = exportFile.toPath();

        try (final BufferedWriter fileWriter = Files.newBufferedWriter(path, UTF_8)) {
          fileWriter.write(output);
        } catch (final IOException e) {
          LOG.error("An error occurred while trying to write to output file", e);
        }
      } else {
        parentCommand.out.println(output);
      }
    }
Run.

@param exportFile the export file
@param outputFunction the output function
app/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java