From a38afbfdf5380131dd313d99ad6f1370ed3082b6 Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Mon, 18 May 2020 14:20:17 +0200 Subject: [PATCH] Clean up help output of main class (installer) If the user passes no arguments, the full help is no longer displayed automatically. Instead, only a short message is displayed that explains how to install the kernel and how to view the full help. There is now also more whitespace in the help text to make it more readable. --- src/main/java/de/prob2/jupyter/Main.java | 35 +++++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/prob2/jupyter/Main.java b/src/main/java/de/prob2/jupyter/Main.java index 4289a04..62b561f 100644 --- a/src/main/java/de/prob2/jupyter/Main.java +++ b/src/main/java/de/prob2/jupyter/Main.java @@ -26,9 +26,23 @@ import com.google.inject.Stage; import io.github.spencerpark.jupyter.channels.JupyterConnection; import io.github.spencerpark.jupyter.kernel.KernelConnectionProperties; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public final class Main { + private static final @NotNull String USAGE_TEXT = "Usage: java -jar prob2-jupyter-kernel-all.jar [--help | install [--user] [JUPYTER] | createKernelSpec KERNELSPECDIR | run CONNECTIONFILE]"; + private static final @NotNull String FULL_HELP_TEXT = "--help: Prints this information.\n" + + "\n" + + "install: Copies the kernel into the ProB home directory, and installs the kernel in Jupyter.\n" + + "\tBy default the kernel spec is installed into the sys.prefix of Jupyter's Python installation. If the sys.prefix is not writable (for example when using the system Python installation instead of a virtual environment), the --user flag can be used to install the kernel only for the current user.\n" + + "\tBy default the command \"jupyter\" is used to install the kernel. If the kernel should be installed in a different Jupyter installation, a different Jupyter command can be passed as an argument to the install command.\n" + + "\n" + + "createKernelSpec: Creates a Jupyter kernel spec for this jar file at the given location.\n" + + "\tThis option is for advanced users or developers, who don't want the jar file to be copied, or who want to install the kernel spec manually.\n" + + "\n" + + "run: Runs the kernel using the given connection file.\n" + + "\tThis option is not meant to be used manually, it is used internally when Jupyter starts the kernel."; + private Main() { super(); @@ -211,17 +225,18 @@ public final class Main { } public static void main(final String[] args) throws IOException, InvalidKeyException, NoSuchAlgorithmException { - if (args.length < 1 || args.length == 1 && "--help".equals(args[0])) { - System.err.println("Usage: java -jar prob2-jupyter-kernel-all.jar [--help | install [--user] [JUPYTER] | createKernelSpec KERNELSPECDIR | run CONNECTIONFILE]"); - System.err.println("--help: Prints this information."); - System.err.println("install: Copies the kernel into the ProB home directory, and installs the kernel in Jupyter."); - System.err.println("\tBy default the kernel spec is installed into the sys.prefix of Jupyter's Python installation. If the sys.prefix is not writable (for example when using the system Python installation instead of a virtual environment), the --user flag can be used to install the kernel only for the current user."); - System.err.println("\tBy default the command \"jupyter\" is used to install the kernel. If the kernel should be installed in a different Jupyter installation, a different Jupyter command can be passed as an argument to the install command."); - System.err.println("createKernelSpec: Creates a Jupyter kernel spec for this jar file at the given location."); - System.err.println("\tThis option is for advanced users or developers, who don't want the jar file to be copied, or who want to install the kernel spec manually."); - System.err.println("run: Runs the kernel using the given connection file."); - System.err.println("\tThis option is not meant to be used manually, it is used internally when Jupyter starts the kernel."); + if (args.length < 1) { + System.err.println(USAGE_TEXT); + System.err.println(); + System.err.println("To install the kernel, run: java -jar prob2-jupyter-kernel-all.jar install"); + System.err.println(); + System.err.println("For a full description of all options, run: java -jar prob2-jupyter-kernel-all.jar --help"); throw die(2); + } else if (args.length == 1 && "--help".equals(args[0])) { + System.out.println(USAGE_TEXT); + System.out.println(); + System.out.println(FULL_HELP_TEXT); + throw die(0); } switch (args[0]) { case "install": -- GitLab