public void run(List<String> args) throws Exception {
        if (raftManager != null) {
            if (snapshotPath != null) {
                throw new RuntimeException("Can't specify both a raft manager and " +
                        "snapshot file reader.");
            }
            initializeWithRaftManager();
        } else if (snapshotPath != null) {
            initializeWithSnapshotFileReader();
        } else {
            throw new RuntimeException("You must specify either a raft manager or a " +
                    "snapshot file reader.");
        }
        loader.installPublishers(Collections.singletonList(publisher)).get(15, TimeUnit.MINUTES);
        if (args == null || args.isEmpty()) {
            // Interactive mode.
            System.out.println("Loading...");
            waitUntilCaughtUp();
            System.out.println("Starting...");
            try (InteractiveShell shell = new InteractiveShell(state)) {
                shell.runMainLoop();
            }
        } else {
            // Non-interactive mode.
            waitUntilCaughtUp();
            Commands commands = new Commands(false);
            try (PrintWriter writer = new PrintWriter(new BufferedWriter(
                    new OutputStreamWriter(System.out, StandardCharsets.UTF_8)))) {
                Commands.Handler handler = commands.parseCommand(args);
                handler.run(Optional.empty(), writer, state);
                writer.flush();
            }
        }
    }
Take the FileLock in the given directory.
shell/src/main/java/org/apache/kafka/shell/MetadataShell.java