-
Notifications
You must be signed in to change notification settings - Fork 64
/
fetch.go
77 lines (64 loc) · 1.65 KB
/
fetch.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
// 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 fetch
import (
"os"
"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
"kraftkit.sh/unikraft/app"
"kraftkit.sh/internal/cli"
)
type Fetch struct {
Architecture string `long:"arch" short:"m" usage:""`
Platform string `long:"plat" short:"p" usage:""`
}
func New() *cobra.Command {
return cli.New(&Fetch{}, cobra.Command{
Short: "Fetch a Unikraft unikernel's dependencies",
Use: "fetch [DIR]",
Aliases: []string{"f"},
Args: cli.MaxDirArgs(1),
Long: heredoc.Doc(`
Fetch a Unikraft unikernel's dependencies`),
Example: heredoc.Doc(`
# Fetch the cwd project
$ kraft build fetch
# Fetch a project at a path
$ kraft build fetch path/to/app`),
Annotations: map[string]string{
"help:group": "build",
},
})
}
func (opts *Fetch) Run(cmd *cobra.Command, args []string) error {
var err error
ctx := cmd.Context()
workdir := ""
if len(args) == 0 {
workdir, err = os.Getwd()
if err != nil {
return err
}
} else {
workdir = args[0]
}
// Initialize at least the configuration options for a project
projectOpts, err := app.NewProjectOptions(
nil,
app.WithWorkingDirectory(workdir),
app.WithDefaultConfigPath(),
app.WithResolvedPaths(true),
app.WithDotConfig(false),
)
if err != nil {
return err
}
// Interpret the application
project, err := app.NewApplicationFromOptions(projectOpts)
if err != nil {
return err
}
return project.Fetch(ctx, nil)
}