From 01c079a697b500ae2e8bbf987ab09be6eac32f82 Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Mon, 30 Aug 2021 20:52:08 +0200 Subject: [PATCH] livebook server: Add `--open-new` flag (#529) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * livebook server: Add `--open-new` flag * Update lib/livebook_cli/server.ex Co-authored-by: Jonatan Kłosko * Update lib/livebook_cli/server.ex * Update changelog Co-authored-by: Jonatan Kłosko --- CHANGELOG.md | 1 + lib/livebook_cli/server.ex | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d942f78aa..8b304b790 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Introduced file system abstraction and an S3 support ([#492](https://github.com/livebook-dev/livebook/pull/492)) - Added support for configuring file systems using env variables ([#498](https://github.com/livebook-dev/livebook/pull/498)) - Added a keyboard shortcut for triggering on-hover docs ([#508](https://github.com/livebook-dev/livebook/pull/508)) +- Added `--open-new` CLI flag to `livebook server` ([#529](https://github.com/livebook-dev/livebook/pull/529)) ### Changed diff --git a/lib/livebook_cli/server.ex b/lib/livebook_cli/server.ex index 25f7588bc..40a7ea37f 100644 --- a/lib/livebook_cli/server.ex +++ b/lib/livebook_cli/server.ex @@ -33,6 +33,7 @@ defmodule LivebookCLI.Server do --no-token Disable token authentication, enabled by default If LIVEBOOK_PASSWORD is set, it takes precedence over token auth --open Open browser window pointing to the application + --open-new Open browser window pointing to a new notebook -p, --port The port to start the web application on, defaults to 8080 --root-path The root path to use for file selection --sname Set a short name for the app distributed node @@ -58,6 +59,14 @@ defmodule LivebookCLI.Server do browser_open(LivebookWeb.Endpoint.access_url()) end + if opts[:open_new] do + LivebookWeb.Endpoint.access_url() + |> URI.parse() + |> Map.update!(:path, &((&1 || "/") <> "explore/notebooks/new")) + |> URI.to_string() + |> browser_open() + end + Process.sleep(:infinity) :error -> @@ -92,6 +101,7 @@ defmodule LivebookCLI.Server do ip: :string, name: :string, open: :boolean, + open_new: :boolean, port: :integer, root_path: :string, sname: :string,