summaryrefslogtreecommitdiffstats
path: root/src/scripts/docker-url-handler.lnav
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xsrc/scripts/docker-url-handler.lnav62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/scripts/docker-url-handler.lnav b/src/scripts/docker-url-handler.lnav
new file mode 100755
index 0000000..a8e9597
--- /dev/null
+++ b/src/scripts/docker-url-handler.lnav
@@ -0,0 +1,62 @@
+#
+# @synopsis: docker-url-handler
+# @description: Internal script to handle opening docker/podman URLs
+#
+
+;SELECT jget(url, '/scheme') AS docker_scheme,
+ jget(url, '/host') AS docker_hostname,
+ jget(url, '/path') AS docker_path
+ FROM (SELECT parse_url($1) AS url)
+
+;SELECT substr($docker_path, 2) AS docker_relpath
+
+;SELECT CASE
+ $docker_hostname
+ WHEN 'compose' THEN (
+ SELECT group_concat(
+ printf(
+ ':sh --name=%s %s-compose -f %s logs --no-log-prefix -f %s',
+ compose_services.key,
+ $docker_scheme,
+ $docker_relpath,
+ compose_services.key
+ ),
+ char(10)
+ ) AS cmds
+ FROM fstat($docker_relpath) AS st,
+ regexp_capture(
+ ifnull(
+ st.data,
+ raise_error(
+ 'Cannot read compose configuration: ' || $docker_relpath,
+ st.error
+ )
+ ),
+ '(?m)(?:^---$)?((?:(?:.|\n)(?!^(?:---|\.\.\.)$))+)'
+ ) AS ydoc,
+ json_each(
+ yaml_to_json(
+ ydoc.content
+ ),
+ '$.services'
+ ) as compose_services
+ WHERE ydoc.match_index = 0
+ AND ydoc.capture_index = 1
+ )
+ ELSE CASE
+ $docker_path
+ WHEN '/' THEN printf(
+ ':sh %s logs -f %s',
+ $docker_scheme,
+ $docker_hostname
+ )
+ ELSE printf(
+ ':sh %s exec %s tail -n +0 -F "%s"',
+ $docker_scheme,
+ $docker_hostname,
+ $docker_path
+ )
+ END
+ END AS cmds
+
+:eval ${cmds}