FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
containerlab/utils/progress/progress.go at main · nemith/containerlab · GitHub
nemith
/
containerlab
Public
forked from
srl-labs/containerlab
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
containerlab
/
utils
/
progress
/
progress.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (49 loc) · 1.62 KB
Breadcrumbs
containerlab
/
utils
/
progress
/
progress.go
Copy path
File metadata and controls
64 lines (49 loc) · 1.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package
progress
import
(
"context"
"io"
"github.com/charmbracelet/log"
"github.com/charmbracelet/x/term"
)
type
Reporter
interface
{
// Start registers an image whose pull is beginning.
Start
(
image
string
)
// Update the progress bar, status is some text
// like "Downloading", "Extracting". percent is the completion percentage (0-1)
Update
(
image
,
status
string
,
percent
float64
)
// Done marks an image pull as done.
Done
(
image
string
,
err
error
)
}
func
New
(
w
io.
Writer
) (
Reporter
,
func
()) {
if
f
,
ok
:=
w
.(
interface
{
Fd
()
uintptr
});
ok
&&
term
.
IsTerminal
(
f
.
Fd
()) {
return
newTUIReporter
(
w
)
}
return
plainReporter
{},
func
() {}
}
// plainReporter emits one log line per image and is used when there is no TTY.
type
plainReporter
struct
{}
func
(
plainReporter
)
Start
(
image
string
) {
log
.
Info
(
"Pulling image"
,
"image"
,
image
)
}
func
(
plainReporter
)
Update
(
_
,
_
string
,
_
float64
) {}
func
(
plainReporter
)
Done
(
image
string
,
err
error
) {
if
err
!=
nil
{
log
.
Error
(
"Failed to pull image"
,
"image"
,
image
,
"err"
,
err
)
return
}
log
.
Info
(
"Done pulling image"
,
"image"
,
image
)
}
type
reporterKey
struct
{}
// NewContext returns a copy of ctx carrying r so that the runtime layer can pick
// it up during PullImage.
func
NewContext
(
ctx
context.
Context
,
r
Reporter
) context.
Context
{
return
context
.
WithValue
(
ctx
,
reporterKey
{},
r
)
}
// FromContext returns the Reporter stored in ctx, or nil if none was set. A nil
// return signals callers to use their legacy single-image progress rendering.
func
FromContext
(
ctx
context.
Context
)
Reporter
{
if
r
,
ok
:=
ctx
.
Value
(
reporterKey
{}).(
Reporter
);
ok
{
return
r
}
return
nil
}
Back
|
FazBrowse Home
|
New Git URL