Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove --open-new option when starting liveserver #960

Merged
merged 12 commits into from
Jan 30, 2022
42 changes: 31 additions & 11 deletions lib/livebook_cli/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ defmodule LivebookCLI.Server do
@impl true
def usage() do
"""
Usage: livebook server [url] [options]
Usage: livebook server [open-command] [--options]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim what about livebook server [options] [open-command]?

I think it's more common to list options first. Also --options looks like it was an actual option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change!


An optional url can be given as argument. If one is given,
a browser window will open importing the given url as a notebook:
An optional open-command can be given as argument. It will open
up a browser window according these rules:

livebook server https://example.com/my-notebook.livemd
* If the open-command is "new", the browser window will point
to a new notebook

* If the open-command is a URL, the notebook at the given URL
will be imported

The open-command runs after the server is started. If a server is
already running, the browser window will point to the server
currently running.

## Available options

Expand All @@ -41,7 +49,6 @@ 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
Expand All @@ -52,6 +59,20 @@ defmodule LivebookCLI.Server do

#{@environment_variables}

## Examples

Starts a server:

livebook server

Starts a server and opens up a browser at a new notebook:

livebook server new

Starts a server and imports the notebook at the given URL:

livebook server https://example.com/my-notebook.livemd

"""
end

Expand Down Expand Up @@ -125,12 +146,12 @@ defmodule LivebookCLI.Server do
if opts[:open] do
Livebook.Utils.browser_open(base_url)
end
end

if opts[:open_new] do
base_url
|> append_path("/explore/notebooks/new")
|> Livebook.Utils.browser_open()
end
defp open_from_options(base_url, _opts, ["new"]) do
base_url
|> append_path("/explore/notebooks/new")
|> Livebook.Utils.browser_open()
end

defp open_from_options(base_url, _opts, [url]) do
Expand All @@ -152,7 +173,6 @@ defmodule LivebookCLI.Server do
ip: :string,
name: :string,
open: :boolean,
open_new: :boolean,
port: :integer,
root_path: :string,
sname: :string,
Expand Down