From 3645bae992faa14c820d76d5879ae102c8c4a9ee Mon Sep 17 00:00:00 2001 From: fj0r <82698591+fj0r@users.noreply.github.com> Date: Mon, 8 May 2023 19:32:14 +0800 Subject: [PATCH] rename registry list to registry show (#480) * rename registry list to registry show Extend its functionality, not just list tags, but also show catalog and manifest, Depending on the number of parameters. * date format by $theme.format show day of the week shortly time_segment --------- Co-authored-by: agent --- modules/docker/docker.nu | 49 ++++++++++++++++++------------- modules/prompt/powerline/power.nu | 3 +- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/modules/docker/docker.nu b/modules/docker/docker.nu index a881b75..60adf9d 100644 --- a/modules/docker/docker.nu +++ b/modules/docker/docker.nu @@ -316,39 +316,48 @@ export def dr [ } } -def "nu-complete registry list" [cmd: string, offset: int] { +def has [name] { + $name in ($in | columns) and (not ($in | get $name | is-empty)) +} + +def "nu-complete registry show" [cmd: string, offset: int] { + let new = ($cmd | str ends-with ' ') let cmd = ($cmd | split row ' ') let url = (do -i { $cmd | get 2 }) let reg = (do -i { $cmd | get 3 }) let tag = (do -i { $cmd | get 4 }) - if ($reg|is-empty) { - if ($env | has 'REGISTRY_TOKEN') { - http get -H [authorization $"Basic ($env.REGISTRY_TOKEN)"] $"($url)/v2/_catalog" - } else { - http get $"($url)/v2/_catalog" - } + let auth = if ($env | has 'REGISTRY_TOKEN') { + [authorization $"Basic ($env.REGISTRY_TOKEN)"] + } else { + [] + } + if ($tag | is-empty) and (not $new) or ($reg | is-empty) { + http get -H $auth $"($url)/v2/_catalog" | get repositories - } else if ($tag|is-empty) { - if ($env | has 'REGISTRY_TOKEN') { - http get $"($url)/v2/($reg)/tags/list" - } else { - http get -H [authorization $"Basic ($env.REGISTRY_TOKEN)"] $"($url)/v2/($reg)/tags/list" - } + } else { + http get -H $auth $"($url)/v2/($reg)/tags/list" | get tags } } -### docker registry list -export def "registry list" [ +### docker registry show +export def "registry show" [ url: string - reg: string@"nu-complete registry list" + reg?: string@"nu-complete registry show" + tag?: string@"nu-complete registry show" ] { - if ($env.REGISTRY_TOKEN? | is-empty) { - http get $"($url)/v2/($reg)/tags/list" + let auth = if ($env | has 'REGISTRY_TOKEN') { + [authorization $"Basic ($env.REGISTRY_TOKEN)"] } else { - http get -H [authorization $"Basic ($env.REGISTRY_TOKEN)"] $"($url)/v2/($reg)/tags/list" + [] + } + if ($reg | is-empty) { + http get -H $auth $"($url)/v2/_catalog" | get repositories + } else if ($tag | is-empty) { + http get -H $auth $"($url)/v2/($reg)/tags/list" | get tags + } else { + http get -e -H [accept 'application/vnd.oci.image.manifest.v1+json'] -H $auth $"($url)/v2/($reg)/manifests/($tag)" | from json } - | get tags } ### buildah diff --git a/modules/prompt/powerline/power.nu b/modules/prompt/powerline/power.nu index 5c28e2a..00bf73e 100644 --- a/modules/prompt/powerline/power.nu +++ b/modules/prompt/powerline/power.nu @@ -78,7 +78,7 @@ def host_abbr [] { def time_segment [] { {|| let theme = $env.NU_POWER_THEME.time - $"($theme.now)(date now | date format '%y-%m-%d_%H:%M:%S')" + $"($theme.now)(date now | date format $theme.format)" } } @@ -551,6 +551,7 @@ export-env { } time: { now: (ansi xterm_tan) + format: '%y%m%d[%w]%H%M%S' } } )