Fork me on GitHub
#babashka
<
2023-02-27
>
István Karaszi14:02:12

Shouldn’t there be a join-paths function in babashka.fs?

2
borkdude14:02:37

@UJSBQNUG6 This is implicitly already there in the form of:

(fs/file .. .. ..)

borkdude14:02:53

or (fs/path .. .. ..), If you want to have a string, call str on it

István Karaszi14:02:08

hmm, okay, that works

István Karaszi14:02:16

don’t you think it would be convenient to have such thing?

borkdude14:02:39

I don't see the need for it since it's already there

István Karaszi14:02:15

okay, I missed the fs/path one

István Karaszi14:02:19

thank you!

👍 2
István Karaszi15:02:19

Is there a way to display a formatted help for a dispatch table with babashka.cli?

2
István Karaszi15:02:58

cli/format-opts is great, but I cannot see how could I display the command table in a nice way

borkdude16:02:23

@UJSBQNUG6 For the command table it's not there (yet), I've done it manually so far

borkdude16:02:24

E.g. in neil: https://github.com/babashka/neil/blob/65a078a24462ab06fc7bc3bd5e240f4adfaa7f8a/src/babashka/neil.clj#L629 I print a global overview and then use format-opts to print the details for each subcommand

István Karaszi16:02:34

there is a bit of duplication here and there

István Karaszi16:02:15

but it works, thanks!

borkdude16:02:05

I suspect there won't be a single way that fits every subcommand need, but maybe it's worth a shot one day

István Karaszi16:02:30

that is fine, I thought there might be something but I am blind as I proved earlier 😄

borkdude16:02:17

no worries, keep asking away ;)

mkvlr18:02:36

when using babashka.http as a library, is it possible to use a newer version of it or will the built-in always be used instead? It seems to be preferring the built-in version so a bb upgrade was a breaking change in our case.

2
borkdude18:02:01

yes, use require + :reload

🙏 2
jjttjj18:02:11

For babashka.fs: Are you interested in a PR that would extend the zip function to allow more flexibility with relative paths? Some ideas in:thread:

jjttjj18:02:28

Right now you must specify relative paths for entries that will be mirrored in the resulting zip. Specifically right now I'm trying to remove this babashka shell call to zip.

(shell {:dir "root-dir"}
  "zip" "myzip.zip"
  "file1.txt"
  "file2.txt"
  "file3.txt")
Which takes the given file in the root-dir and puts them in a zip. Unfortunately zip cli calls aren't optimal for cross platform things. So one way to support this in fs is have the zip function take an option that essentially "relativizes" the paths when putting them in the zip.
(fs/zip "myzip.zip" ["root-dir/file1.txt"
                     "root-dir/file2.txt"
                     "root-dir/file3.txt"]
  {:relativize-entry-paths "root-dir"})
Another more general option might be to allow a function to be passed to transform an entry to the path that will appear in the zip, ie
(fs/zip "myzip.zip" ["root-dir/file1.txt"
                     "root-dir/file2.txt"
                     "root-dir/file3.txt"]
  {:entry-path (fn [p] (fs/relativize "root-dir" p))})
Another idea is to allow a map for the entries themselves, mapping the path on the filesystem to the path it will appear in the zip:
(fs/zip "myzip.zip" {"file1.txt" "path/for/file1.txt"
                     "file2.txt" "another/path/file2.txt"})

jjttjj18:02:16

I sort of like the last option the best, but interested in any input. Also open to the idea that this is getting too fancy with zipping functionality for a general file library, and it should be somewhere else.

borkdude18:02:29

> Another more general option might be to allow a function to be passed to transform an entry to the path that will appear in the zip, I think this will be the most flexible option

borkdude18:02:21

but do I understand correctly that you just want to get rid of the parent directory, like in that issue?

jjttjj19:02:19

I want to use a different directory as the parent directory, which I think is different

jjttjj19:02:31

I have stuff/f1.txt and i want it as f1.txt in the zip

borkdude19:02:03

yes, this is what I mean with "elide parent directory" in the issue

borkdude19:02:09

you want to elide stuff in the zip

borkdude19:02:32

but a :path-fn or so would be good, then indeed you can call relativize

jjttjj19:02:18

One thing I realized I missed is the case where a directory is specified as an entry. Presumably the path-fn in that case would return the entry path of the directory. And then the contents of that dir are all given a path relative to that in the zip

borkdude19:02:38

Maybe best to try out in an experimental PR or so

jjttjj19:02:53

will do, thanks for the input!

borkdude22:02:57

@U064UGEUQ I went ahead and added both :root and :path-fn - it's released, see #C06MAR553

borkdude22:02:15

I will release a new bb tomorrow morning with this included as well

jjttjj22:02:44

Awesome, thanks!