This repository was archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathdev.go
More file actions
68 lines (59 loc) · 2.7 KB
/
Copy pathdev.go
File metadata and controls
68 lines (59 loc) · 2.7 KB
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
package cli
import (
"io"
cli "github.com/acorn-io/acorn/pkg/cli/builder"
"github.com/acorn-io/acorn/pkg/dev"
"github.com/acorn-io/acorn/pkg/imagesource"
"github.com/spf13/cobra"
)
func NewDev(c CommandContext) *cobra.Command {
cmd := cli.Command(&Dev{out: c.StdOut, client: c.ClientFactory}, cobra.Command{
Use: "dev [flags] IMAGE|DIRECTORY [acorn args]",
SilenceUsage: true,
Short: "Run an app from an image or Acornfile in dev mode or attach a dev session to a currently running app",
ValidArgsFunction: newCompletion(c.ClientFactory, imagesCompletion(true)).withSuccessDirective(cobra.ShellCompDirectiveDefault).withShouldCompleteOptions(onlyNumArgs(1)).complete,
Example: `
acorn dev <IMAGE>
acorn dev .
acorn dev --name wandering-sound
acorn dev --name wandering-sound <IMAGE>
`})
// This will produce an error if the volume flag doesn't exist or a completion function has already
// been registered for this flag. Not returning the error since neither of these is likely occur.
if err := cmd.RegisterFlagCompletionFunc("volume", newCompletion(c.ClientFactory, volumeFlagClassCompletion).complete); err != nil {
cmd.Printf("Error registering completion function for -v flag: %v\n", err)
}
// This will produce an error if the computeclass flag doesn't exist or a completion function has already
// been registered for this flag. Not returning the error since neither of these is likely occur.
if err := cmd.RegisterFlagCompletionFunc("compute-class", newCompletion(c.ClientFactory, computeClassFlagCompletion).complete); err != nil {
cmd.Printf("Error registering completion function for --compute-class flag: %v\n", err)
}
cmd.PersistentFlags().Lookup("dangerous").Hidden = true
cmd.Flags().SetInterspersed(false)
return cmd
}
type Dev struct {
RunArgs
BidirectionalSync bool `usage:"In interactive mode download changes in addition to uploading" short:"b"`
Replace bool `usage:"Replace the app with only defined values, resetting undefined fields to default values" json:"replace,omitempty"` // Replace sets patchMode to false, resulting in a full update, resetting all undefined fields to their defaults
out io.Writer
client ClientFactory
}
func (s *Dev) Run(cmd *cobra.Command, args []string) error {
c, err := s.client.CreateDefault()
if err != nil {
return err
}
imageSource := imagesource.NewImageSource(s.File, args, s.Profile, nil)
opts, err := s.ToOpts(cmd.Context(), c)
if err != nil {
return err
}
return dev.Dev(cmd.Context(), c, &dev.Options{
ImageSource: imageSource,
Run: opts,
Replace: s.Replace,
Dangerous: s.Dangerous,
BidirectionalSync: s.BidirectionalSync,
})
}