-
Notifications
You must be signed in to change notification settings - Fork 439
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
Conversation
@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
Add if-else clause to handle `:notebook` switch in open_from_options/2. Imports the notebook for now, rather than opening it.
@jonatanklosko |
lib/livebook_cli/server.ex
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🙈
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@aar2dee2 yup that's the right direction, just a few tiny comments :) |
Co-authored-by: Jonatan Kłosko <[email protected]>
added as helper function to aid `:notebook` flag in Livebook CLI
Co-authored-by: Jonatan Kłosko <[email protected]>
Co-authored-by: José Valim <[email protected]>
Co-authored-by: José Valim <[email protected]>
Co-authored-by: José Valim <[email protected]>
lib/livebook_cli/server.ex
Outdated
@@ -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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it :)
--notebook
option in livebook CLI
💚 💙 💜 💛 ❤️ |
enjoyed working on this. thanks a lot for guiding me :)
|
@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. |
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 thatopen_from_options/2
is called. We're modifying theroot_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 :)