public KernelApplication AddInstallCommand()

in src/KernelApplication.cs [153:244]


        public KernelApplication AddInstallCommand(Action<CommandLineApplication>? configure = null)
        {
            var installCmd = this.Command(
                "install",
                cmd =>
                {
                    cmd.HelpOption();
                    cmd.Description = $"Installs the {properties.FriendlyName} ({properties.KernelName}) kernel into Jupyter.";
                    var developOpt = cmd.Option(
                        "--develop",
                        "Installs a kernel spec that runs against this working directory. Useful for development only.",
                        CommandOptionType.NoValue
                    );
                    var userOpt = cmd.Option(
                        "--user",
                        "Installs the kernel for the current user only.",
                        CommandOptionType.NoValue
                    );
                    var sysPrefixOpt = cmd.Option(
                        "--sys-prefix",
                        "Installs the kernel into the prefix given by Python's sys.prefix. Useful with conda env/venv.",
                        CommandOptionType.NoValue
                    );
                    var logLevelOpt = cmd.Option<LogLevel>(
                        "-l|--log-level <LEVEL>",
                        "Level of logging messages to emit to the console. On development mode, defaults to Information.",
                        CommandOptionType.SingleValue
                    );
                    var prefixOpt = cmd.Option<string>(
                        "--prefix <PREFIX>",
                        "Prefix to use when installing the kernel into Jupyter. See `jupyter kernelspec install --help` for details.",
                        CommandOptionType.SingleValue
                    );
                    var toolPathOpt = cmd.Option<string>(
                        "--path-to-tool <PATH>",
                        "Specifies an explicit path to the kernel tool being installed, rather than using the .NET command. " +
                        "This option is incompatible with --develop, and isn't typically needed except in CI builds or other automated environments.",
                        CommandOptionType.SingleValue
                    );
                    var extraInstallArgsOpt = cmd.Option<string>(
                        "--extra-install-arg <ARG>",
                        "Specifies an extra argument to pass to Jupyter when installing this kernel.",
                        CommandOptionType.MultipleValue
                    );
                    var nameOpt = cmd.Option<string>(
                        "--name <NAME>",
                        $"Specifies the name of the kernel to be installed; if not specified, defaults to {properties.KernelName}.",
                        CommandOptionType.SingleOrNoValue
                    );
                    cmd.OnExecute(() =>
                    {
                        var develop = developOpt.HasValue();
                        var logLevel =
                            logLevelOpt.HasValue()
                            ? logLevelOpt.ParsedValue
                            : (develop ? LogLevel.Information : LogLevel.Error);
                        var prefix = prefixOpt.HasValue() ? prefixOpt.Value() : null;
                        var extraInstallArgs = extraInstallArgsOpt
                            .Values
                            .ToList();
                        if (userOpt.HasValue())
                        {
                            extraInstallArgs.Add("--user");
                        }
                        if (sysPrefixOpt.HasValue())
                        {
                            extraInstallArgs.Add("--sys-prefix");
                        }
                        return ReturnExitCode(() => InstallKernelSpec(
                            develop, logLevel,
                            prefix: prefix,
                            extraInstallArgs: extraInstallArgs,
                            additionalFiles: additionalFiles,
                            additionalKernelArguments:
                                additionalKernelArgumentSources
                                .SelectMany(source => source()),
                            pathToTool:
                                toolPathOpt.HasValue()
                                ? toolPathOpt.ParsedValue
                                : null,
                            kernelName:
                                nameOpt.HasValue()
                                ? nameOpt.ParsedValue
                                : null
                        ));
                    });
                }
            );
            configure?.Invoke(installCmd);

            return this;
        }