This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
create.go
71 lines (56 loc) · 1.61 KB
/
create.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
package main
import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
"github.com/spf13/cobra"
"github.com/cnabio/duffle/pkg/duffle/home"
"github.com/cnabio/duffle/pkg/duffle/manifest"
)
const createDesc = `
This command creates a bundle directory along with a minimal duffle.json file and a cnab directory with a Dockerfile for the invocation image
For example, 'duffle create foo' will create a directory structure that looks like this:
foo/
|
|- duffle.json # The build configuration file
|
|- cnab/ # Contains invocation image
|
|- Dockerfile # Dockerfile for invocation image
If directories in the given path do not exist, it will attempt to create them. If the given path exists and there are files in that directory, conflicting files will be overwritten but other files will be left alone.
`
type createCmd struct {
path string
home home.Home
out io.Writer
}
func newCreateCmd(w io.Writer) *cobra.Command {
create := &createCmd{out: w}
cmd := &cobra.Command{
Use: "create [PATH]",
Short: "scaffold a bundle",
Long: createDesc,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("this command requires the path")
}
create.home = home.Home(homePath())
create.path = args[0]
return create.run()
},
}
return cmd
}
func (c *createCmd) run() error {
path, err := filepath.Abs(c.path)
if err != nil {
return err
}
fmt.Fprintf(c.out, "Creating %s\n", c.path)
if err := os.Mkdir(path, 0755); err != nil {
return err
}
return manifest.Scaffold(path)
}