Class CommandLine

java.lang.Object
ch.autumo.ui.utils.CommandLine

public final class CommandLine extends Object
Generic command-line handling for an autumo-ui application.

An application accepts a file to open in two shapes:

  • --open <file> — the explicit form;
  • <file> — the bare file path a packaged (jpackage) launcher receives when the user double-clicks a registered file or uses Open With. The OS hands the selected file straight to the application as the first argument, so no option is present.

A bare argument is only treated as a file when its name carries one of the registered extensions. The framework registers none by itself: an application declares which file endings it can open via BaseApp.registerOpenExtension(String). Without any registration no bare argument is ever accepted, so unrelated arguments (JavaFX or JVM options) are never mistaken for a file. The explicit --open form accepts any path, because the intent is then unambiguous.

  • Field Details

  • Method Details

    • hasExtension

      public static boolean hasExtension(String name, Collection<String> extensions)
      Whether a file name carries one of the given extensions.
      Parameters:
      name - file name or path to inspect (may be null)
      extensions - registered extensions, each with a leading dot (e.g. ".ifcx"); may be null or empty, in which case nothing matches
      Returns:
      true if the name ends with one of the extensions (case-insensitive)
    • openTarget

      public static Path openTarget(List<String> args, Collection<String> extensions)
      Picks the file to open from the raw command line arguments.

      Recognises --open <file> and a bare <file> whose extension is registered (see the class comment). Any other argument — notably one starting with - such as --verbose — yields null, so the caller can keep handling its own options.

      Parameters:
      args - raw command line arguments (may be null or empty)
      extensions - registered extensions, each with a leading dot; may be null or empty
      Returns:
      the file to open, or null when the command line carries none