/
describe-script.go
47 lines (41 loc) · 1.09 KB
/
describe-script.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
package cmd
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/gitpod-io/leeway/pkg/prettyprint"
)
// describeScriptCmd represents the describeTree command
var describeScriptCmd = &cobra.Command{
Use: "script",
Short: "Describes a script",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
_, _, script, exists := getTarget(args, true)
if !exists || script == nil {
log.Fatal("needs a script")
}
w := getWriterFromFlags(cmd)
if w.Format == prettyprint.TemplateFormat && w.FormatString == "" {
w.FormatString = `Name:{{"\t"}}{{ .FullName }}
{{ if .Description }}Description:{{"\t"}}{{ .Description }}{{ end }}
Type:{{"\t"}}{{ .Type }}
Workdir Layout:{{"\t"}}{{ .WorkdirLayout }}
{{ if .Dependencies -}}
Dependencies:
{{- range $k, $v := .Dependencies }}
{{"\t"}}{{ $v.FullName -}}{{"\t"}}{{ $v.Version -}}
{{ end -}}
{{ end }}
`
}
desc := newScriptDescription(script)
err := w.Write(desc)
if err != nil {
log.Fatal(err)
}
},
}
func init() {
describeCmd.AddCommand(describeScriptCmd)
addFormatFlags(describeScriptCmd)
}