diff options
Diffstat (limited to 'examples/tomo-install/tomo-install.tm')
| -rw-r--r-- | examples/tomo-install/tomo-install.tm | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/examples/tomo-install/tomo-install.tm b/examples/tomo-install/tomo-install.tm index 0be05619..0a255987 100644 --- a/examples/tomo-install/tomo-install.tm +++ b/examples/tomo-install/tomo-install.tm @@ -12,13 +12,13 @@ _HELP := " func find_urls(path:Path -> [Text]): urls : @[Text] = @[] - if path:is_directory(): - for f in path:children(): - urls:insert_all(find_urls(f)) - else if path:is_file() and path:extension() == ".tm": - for line in path:by_line()!: - if captures := line:pattern_captures($Pat/use{space}{url}/) or line:pattern_captures($Pat/{id}{space}:={space}use{space}{url}/): - urls:insert(captures[-1]) + if path.is_directory(): + for f in path.children(): + urls.insert_all(find_urls(f)) + else if path.is_file() and path.extension() == ".tm": + for line in path.by_line()!: + if captures := line.pattern_captures($Pat/use{space}{url}/) or line.pattern_captures($Pat/{id}{space}:={space}use{space}{url}/): + urls.insert(captures[-1]) return urls func main(paths:[Path]): @@ -27,27 +27,27 @@ func main(paths:[Path]): urls := (++: find_urls(p) for p in paths) or [] - github_token := (~/.config/tomo/github-token):read() + github_token := (~/.config/tomo/github-token).read() - (~/.local/share/tomo/installed):create_directory() - (~/.local/share/tomo/lib):create_directory() + (~/.local/share/tomo/installed).create_directory() + (~/.local/share/tomo/lib).create_directory() for url in urls: original_url := url - url_without_protocol := url:trim_pattern($Pat"http{0-1 s}://", right=no) - hash := $Shell@(echo -n @url_without_protocol | sha256sum):get_output()!:slice(to=32) - if (~/.local/share/tomo/installed/$hash):is_directory(): + url_without_protocol := url.trim_pattern($Pat"http{0-1 s}://", right=no) + hash := $Shell@(echo -n @url_without_protocol | sha256sum).get_output()!.slice(to=32) + if (~/.local/share/tomo/installed/$hash).is_directory(): say("Already installed: $url") skip alias : Text? = none curl_flags := ["-L"] - if github := url_without_protocol:pattern_captures($Pat"github.com/{!/}/{!/}#{..}"): + if github := url_without_protocol.pattern_captures($Pat"github.com/{!/}/{!/}#{..}"): user := github[1] repo := github[2] tag := github[3] url = "https://api.github.com/repos/$user/$repo/tarball/$tag" - alias = "$(repo:without_prefix("tomo-")).$(tag).$(user)" + alias = "$(repo.without_prefix("tomo-")).$(tag).$(user)" if github_token: curl_flags ++= ["-H", "Authorization: Bearer $github_token"] curl_flags ++= [ @@ -55,7 +55,7 @@ func main(paths:[Path]): "-H", "X-GitHub-Api-Version: 2022-11-28", ] - (~/.local/share/tomo/downloads/$hash):create_directory() + (~/.local/share/tomo/downloads/$hash).create_directory() say($Shell@` set -euo pipefail cd ~/.local/share/tomo/downloads/@hash @@ -67,7 +67,7 @@ func main(paths:[Path]): else ln -f -s ../installed/@hash/lib@hash.so ~/.local/share/tomo/lib/lib@hash.so fi - `:get_output()!) + `.get_output()!) if alias: say($Shell( @@ -78,7 +78,7 @@ func main(paths:[Path]): else ln -f -s lib@hash.so ~/.local/share/tomo/lib/lib@alias.so fi - ):get_output()!) + ).get_output()!) say("$\[1]Installed $url!$\[]") |
