-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Provide a way to detect the invoked script #95
Comments
Came up with the following hack to get the "top level" nbb file (as in python's top level module concept): (require '["path" :as path])
(defn top-level-nbb-file []
(let [nbb-index (.indexOf js/process.argv "/usr/bin/nbb")] ;;get the index of nbb in the args array
(if (> nbb-index 0)
(get js/process.argv (inc nbb-index))))) ;; get the path of the script passed to nbb
(if-let [tl (top-level-nbb-file)]
(if (= *file* (path/resolve tl))
(-main))) |
I'd also find this helpful. My workaround is |
How about nbb providing a fn similar to |
Yes, we can add a function for this to |
Thanks @cldwalker - I used your hack in a project today. |
@borkdude Is this still something that needs work? |
@bolivier indeed |
@borkdude I think most of the value here can be achieved relatively easily. Looks like (if *file*
:from-a-file
:repl) Although it might be wise to set that value to Let me know what sounds good to you and I can open a PR. |
The check we do in babashka is:
Just checking Therefore I'd say we store the invoked file, as parsed from the command line options somewhere (I think it's already somewhere in a stored opts map) and we make a function in nbb.core: The |
Similar to
(= *file (System/getProperty "babashka.file"))
Also see https://stackoverflow.com/questions/6398196/detect-if-called-through-require-or-directly-by-command-line
We can make a function in nbb.core to return the invoked file:
Still have to come up with a good name.
The text was updated successfully, but these errors were encountered: