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

Add url arg to the CLI #947

Merged
merged 24 commits into from
Jan 29, 2022
Merged

Add url arg to the CLI #947

merged 24 commits into from
Jan 29, 2022

Conversation

aar2dee2
Copy link
Contributor

Issue #635

@jonatanklosko
We've added a :notebook clause to opts_to_config/2 to handle the :notebook switch. This returns opts with {:open, true} added so that open_from_options/2 is called. We're modifying the root_path to point to the notebook specified by the user. Please let me know if any edits to be made.

@ryg-git thank you for working on this with me :)

@ryg-git - I added the notebook option in the usage/0 function (line 38) and in switches (line 142).
The code for opening a notebook directly can be included in the `open_from_options/2` function, I think. We can have a third if-else clause for `opts[:notebook]`, append the filename to base url and then use Livebook.Utils.browser_open(). 
What do you think?
@ryg-git 

I've added the :notebook clause for opts_to_config/2 (line 217).
Since we want to open the notebook after changing the root path, and the `--open` flag may not be entered by user when using `--notebook`, I'm adding `{:open, true}` in the `opts` list. I've removed the if-else clause for `opts[:notebook]` added earlier in open_from_options/1, since that would be incorrect as the `:notebook` flag is not of boolean type.
add colon to make root_path an atom
@CLAassistant
Copy link

CLAassistant commented Jan 28, 2022

CLA assistant check
All committers have signed the CLA.

@jonatanklosko
Copy link
Member

Hey @aar2dee2 and @ryg-git, thanks for working on this! Just left a comment, let me know if anything is not clear :)

Add if-else clause to handle `:notebook` switch in open_from_options/2. Imports the notebook for now, rather than opening it.
@aar2dee2
Copy link
Contributor Author

aar2dee2 commented Jan 28, 2022

@jonatanklosko
made some edits based on your comment. does this do as intended?

@@ -35,6 +35,7 @@ defmodule LivebookCLI.Server do
--name Set a name for the app distributed node
--no-token Disable token authentication, enabled by default
If LIVEBOOK_PASSWORD is set, it takes precedence over token auth
--notebook Open browser window pointing to notebook specified
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
--notebook Open browser window pointing to notebook specified
--open-notebook Open browser window pointing to the given notebook

A bit longer, but consistent with the other ones. If someone uses this frequently, they are likely to setup an alias anyway, @josevalim any preference?

Copy link
Contributor

Choose a reason for hiding this comment

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

my unsolicited opinion is +1, I was gonna propose the same. Another idea is --open-file. It's a separate discussion but would it make sense to have $ livebook server --open-url https://github.com/... too? If so perhaps --open-file makes a bit more sense.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, we could make --open-notebook accept both file path and URL, not sure if that's better or worse. Note that once we do #927 then the semantics would be different, from URL we just import, from file we actually open, but that's a sidenote.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I think we could check whether given argument starts with http(s):// (maybe we special case livebook:// too, dunno, probably not as it's supposed to be internal) and if so it's an url, otherwise it's a local file. I kinda like the more explicit --open-file & --open-url but a single option that handles both might be something more users would expect.

Copy link
Member

Choose a reason for hiding this comment

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

Hopefully @josevalim has a strong preference 🙈

Copy link
Member

@jonatanklosko jonatanklosko Jan 28, 2022

Choose a reason for hiding this comment

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

So I'm thinking we can add --open-file and --import-url in this PR, but both of them import, then in a follow up PR we add an endpoint for opening local files and use it for --open-file and #927. Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm, to be honest, I am not sure. This sounds verbose. What if instead we make this an argument to livebook server? Such as livebook server Foo.livemd? And if a URL is given, we import?

then this PR supports only URLs and we add files later?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, we also have this option. The good thing is that we avoid the ambiguous open/import wording altogether, so it's definitely less confusing. The only question is if we would want to use argv for anything else in the future, but I cannot think of an obvious case. @wojtekmach?

Copy link
Contributor

@wojtekmach wojtekmach Jan 28, 2022

Choose a reason for hiding this comment

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

Cant think of any other use case for argv. Yet another option, to not paint ourselves into a wall, is a more generic —-url URL, a file path is an url after all too. But maybe it could be mistaken for the url of the server and not of the thing we want to access. So yeah argv sounds good to me.

Copy link
Member

Choose a reason for hiding this comment

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

Fantastic, let's do argv then!

@aar2dee2 sorry for revisiting just now 🙈 To sum up, the idea is to have livebook server [options] [.livemd url], so we need to get argv from option parser and if there is anything we will import the URL.

Then in a separate PR we will extend it to [.livemd file or url], and when file is given we "Open" it instead of importing.

@jonatanklosko
Copy link
Member

@aar2dee2 yup that's the right direction, just a few tiny comments :)

aar2dee2 and others added 3 commits January 28, 2022 19:47
aar2dee2 and others added 3 commits January 29, 2022 14:14
Co-authored-by: José Valim <[email protected]>
Co-authored-by: José Valim <[email protected]>
Co-authored-by: José Valim <[email protected]>
@@ -67,7 +62,11 @@ defmodule LivebookCLI.Server do
case check_endpoint_availability(base_url) do
:livebook_running ->
IO.puts("Livebook already running on #{base_url}")
open_from_options(base_url, opts, extra_args)
if length(exta_args) > 1 do
print_error("Too many arguments entered. Please ensure only one argument is used to specify the file path and all other arguments are preceded by the relevant switch")
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of handling it here, you can handle it as a catch-all on open_from_options. This way there is no duplication either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it :)

@josevalim josevalim changed the title add --notebook option in livebook CLI Add url arg to the CLI Jan 29, 2022
@josevalim josevalim merged commit 4202840 into livebook-dev:main Jan 29, 2022
@josevalim
Copy link
Contributor

💚 💙 💜 💛 ❤️

@aar2dee2
Copy link
Contributor Author

enjoyed working on this. thanks a lot for guiding me :)

💚 💙 💜 💛 ❤️

@ryg-git
Copy link
Contributor

ryg-git commented Jan 29, 2022

@aar2dee2 thank you for doing all of the work, I am sorry I couldn't be of much help as I was busy in some personal work, thanks.

@aar2dee2
Copy link
Contributor Author

@aar2dee2 thank you for doing all of the work, I am sorry I couldn't be of much help as I was busy in some personal work, thanks.

@ryg-git no worries. hope to work with you again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants