Class BitwardenCLIManager

java.lang.Object
com.mwdle.bitwarden.cli.BitwardenCLIManager

public final class BitwardenCLIManager extends Object
A thread-safe singleton that manages the lifecycle of the Bitwarden CLI executable.

This class handles OS detection, on-demand downloading from the official Bitwarden site, extraction of the executable, and provides a reliable, cached path for other components to use. It ensures the CLI is always available when needed, attempting to download it if it's missing.

  • Method Details

    • getInstance

      public static BitwardenCLIManager getInstance()
      Provides global access to the single instance of this manager.
      Returns:
      The singleton instance of BitwardenCLIManager.
    • downloadLatestExecutable

      public boolean downloadLatestExecutable()
      Forces a download of the latest Bitwarden CLI, overwriting any existing version.

      This method performs a blocking, network-intensive operation performed in a thread-safe manner.

      Returns:
      true on success, false on failure.
    • provisionExecutable

      public boolean provisionExecutable()
      Ensures the Bitwarden CLI executable is present, downloading it if it does not exist.

      This is the primary method for automatic, on-demand setup. It first checks if the executable exists and only performs the expensive download operation if necessary.

      Returns:
      true if the executable is present or was successfully downloaded, otherwise false.
    • getExecutablePath

      public String getExecutablePath()
      Gets the absolute path to the managed Bitwarden CLI executable.

      This is the main entry point for getting the path to the CLI. It uses an in-memory cache for performance and is self-healing: if the executable is missing for any reason, it will automatically attempt to provision it on-demand.

      Returns:
      The full path to the bw executable.
      Throws:
      IllegalStateException - if the executable is not found and cannot be downloaded.