Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new cmd: container-log-trunc #761

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
new cmd: container-log-trunc
clean container-log-namespace
  • Loading branch information
nashvi committed Feb 20, 2024
commit 56597f3bcfd89f1bba10cd10590e0967c16abb8b
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