class RemoveCustomsCommand extends ElasticsearchNodeCommand {

    static final String CUSTOMS_REMOVED_MSG = "Customs were successfully removed from the cluster state";
    static final String CONFIRMATION_MSG =
        DELIMITER +
            "\n" +
            "You should only run this tool if you have broken custom metadata in the\n" +
            "cluster state that prevents the cluster state from being loaded.\n" +
            "This tool can cause data loss and its use should be your last resort.\n" +
            "\n" +
            "Do you want to proceed?\n";

    private final OptionSpec<String> arguments;

    public RemoveCustomsCommand() {
        super("Removes custom metadata from the cluster state");
        arguments = parser.nonOptions("custom metadata names");
    }

    @Override
    protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env)
        throws IOException, UserException {<FILL_FUNCTION_BODY>}
}

        final List<String> customsToRemove = arguments.values(options);
        if (customsToRemove.isEmpty()) {
            throw new UserException(ExitCodes.USAGE, "Must supply at least one custom metadata name to remove");
        }

        final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);

        terminal.println(Terminal.Verbosity.VERBOSE, "Loading cluster state");
        final Tuple<Long, ClusterState> termAndClusterState = loadTermAndClusterState(persistedClusterStateService, env);
        final ClusterState oldClusterState = termAndClusterState.v2();
        terminal.println(Terminal.Verbosity.VERBOSE, "custom metadata names: " + oldClusterState.metadata().customs().keys());
        final Metadata.Builder metaDataBuilder = Metadata.builder(oldClusterState.metadata());
        for (String customToRemove : customsToRemove) {
            boolean matched = false;
            for (ObjectCursor<String> customKeyCur : oldClusterState.metadata().customs().keys()) {
                final String customKey = customKeyCur.value;
                if (Regex.simpleMatch(customToRemove, customKey)) {
                    metaDataBuilder.removeCustom(customKey);
                    if (matched == false) {
                        terminal.println("The following customs will be removed:");
                    }
                    matched = true;
                    terminal.println(customKey);
                }
            }
            if (matched == false) {
                throw new UserException(ExitCodes.USAGE,
                    "No custom metadata matching [" + customToRemove + "] were found on this node");
            }
        }
        final ClusterState newClusterState = ClusterState.builder(oldClusterState).metadata(metaDataBuilder.build()).build();
        terminal.println(Terminal.Verbosity.VERBOSE,
            "[old cluster state = " + oldClusterState + ", new cluster state = " + newClusterState + "]");

        confirm(terminal, CONFIRMATION_MSG);

        try (PersistedClusterStateService.Writer writer = persistedClusterStateService.createWriter()) {
            writer.writeFullStateAndCommit(termAndClusterState.v1(), newClusterState);
        }

        terminal.println(CUSTOMS_REMOVED_MSG);
    
<methods>public void <init>(java.lang.String) ,public static org.elasticsearch.cluster.ClusterState clusterState(org.elasticsearch.env.Environment, org.elasticsearch.gateway.PersistedClusterStateService.OnDiskState) ,public static org.elasticsearch.gateway.PersistedClusterStateService createPersistedClusterStateService(org.elasticsearch.common.settings.Settings, java.nio.file.Path[]) throws java.io.IOException,public final void execute(org.elasticsearch.cli.Terminal, OptionSet, org.elasticsearch.env.Environment) throws java.lang.Exception,public static Tuple<java.lang.Long,org.elasticsearch.cluster.ClusterState> loadTermAndClusterState(org.elasticsearch.gateway.PersistedClusterStateService, org.elasticsearch.env.Environment) throws java.io.IOException<variables>public static final java.lang.String ABORTED_BY_USER_MSG,public static final java.lang.String CS_MISSING_MSG,protected static final java.lang.String DELIMITER,public static final java.lang.String FAILED_TO_OBTAIN_NODE_LOCK_MSG,private static final Logger LOGGER,protected static final org.elasticsearch.common.xcontent.NamedXContentRegistry NAMED_X_CONTENT_REGISTRY,public static final java.lang.String NO_NODE_FOLDER_FOUND_MSG,public static final java.lang.String NO_NODE_METADATA_FOUND_MSG,public static final java.lang.String STOP_WARNING_MSG