Skip to content

Commit

Permalink
new cmd: container-log-trunc (nushell#761)
Browse files Browse the repository at this point in the history
clean container-log-namespace

Co-authored-by: nash <[email protected]>
  • Loading branch information
fj0r and nashvi authored Feb 20, 2024
1 parent e8f4d74 commit 144f3fe
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions modules/docker/docker.nu
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,27 @@ def "nu-complete docker images" [] {
| each {|x| $"($x.REPOSITORY):($x.TAG)"}
}


# container log
export def container-log [ctn: string@"nu-complete docker containers"
export def container-log [
ctn: string@"nu-complete docker containers"
-l: int = 100 # line
-n: string@"nu-complete docker ns" # namespace
] {
let l = if $l == 0 { [] } else { [--tail $l] }
^$env.docker-cli logs -f ...$l $ctn
^$env.docker-cli ...($n | with-flag -n) logs -f ...$l $ctn
}

# container log with namespace
export def container-log-namespace [ctn: string@"nu-complete docker containers"
-l: int = 100 # line
export def container-log-trunc [
ctn: string@"nu-complete docker containers"
-n: string@"nu-complete docker ns" # namespace
] {
let l = if $l == 0 { [] } else { [--tail $l] }
^$env.docker-cli ...($n | with-flag -n) logs -f ...$l $ctn
if $env.docker-cli == 'podman' {
print -e $'(ansi yellow)podman(ansi dark_gray) isn’t supported(ansi reset)'
} else {
let f = ^$env.docker-cli ...($n | with-flag -n) inspect --format='{{.LogPath}}' $ctn
truncate -s 0 $f
}
}

# attach container
Expand Down Expand Up @@ -498,7 +504,7 @@ export def "bud rm" [
export alias dp = container-list
export alias di = image-list
export alias dl = container-log
export alias dln = container-log-namespace
export alias dlt = container-log-trunc
export alias da = container-attach
export alias dcp = container-copy-file
export alias dcr = container-remove
Expand Down

0 comments on commit 144f3fe

Please sign in to comment.