-
Notifications
You must be signed in to change notification settings - Fork 64
/
update.go
80 lines (69 loc) · 1.92 KB
/
update.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file expect in compliance with the License.
package update
import (
"context"
"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
"kraftkit.sh/cmdfactory"
"kraftkit.sh/config"
"kraftkit.sh/log"
"kraftkit.sh/pack"
"kraftkit.sh/packmanager"
"kraftkit.sh/tui/processtree"
)
type Update struct {
Manager string `long:"manager" short:"m" usage:"Force the handler type" default:"manifest" local:"true"`
}
func New() *cobra.Command {
return cmdfactory.New(&Update{}, cobra.Command{
Short: "Retrieve new lists of Unikraft components, libraries and packages",
Use: "update [FLAGS]",
Long: heredoc.Doc(`
Retrieve new lists of Unikraft components, libraries and packages.`),
Aliases: []string{"u"},
Example: heredoc.Doc(`
$ kraft pkg update
`),
Annotations: map[string]string{
cmdfactory.AnnotationHelpGroup: "pkg",
},
})
}
func (opts *Update) Run(cmd *cobra.Command, args []string) error {
var err error
ctx := cmd.Context()
pm := packmanager.G(ctx)
// Force a particular package manager
if len(opts.Manager) > 0 && opts.Manager != "auto" {
pm, err = pm.From(pack.PackageFormat(opts.Manager))
if err != nil {
return err
}
}
parallel := !config.G[config.KraftKit](ctx).NoParallel
norender := log.LoggerTypeFromString(config.G[config.KraftKit](ctx).Log.Type) != log.FANCY
model, err := processtree.NewProcessTree(
ctx,
[]processtree.ProcessTreeOption{
// processtree.WithVerb("Updating"),
processtree.IsParallel(parallel),
processtree.WithRenderer(norender),
},
[]*processtree.ProcessTreeItem{
processtree.NewProcessTreeItem(
"Updating...",
"",
func(ctx context.Context) error {
return pm.Update(ctx)
},
),
}...,
)
if err != nil {
return err
}
return model.Start()
}