/
get_quickstarts.go
96 lines (81 loc) · 2.87 KB
/
get_quickstarts.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package get
import (
"fmt"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/quickstarts"
"github.com/spf13/cobra"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
)
//GetQuickstartsOptions - the command line options
type GetQuickstartsOptions struct {
Options
GitHubOrganisations []string
Filter quickstarts.QuickstartFilter
ShortFormat bool
IgnoreTeam bool
}
var (
getQuickstartsLong = templates.LongDesc(`
Display the available quickstarts
`)
getQuickstartsExample = templates.Examples(`
# List all the available quickstarts
jx get quickstarts
`)
)
//NewCmdGetQuickstarts creates the command
func NewCmdGetQuickstarts(commonOpts *opts.CommonOptions) *cobra.Command {
options := &GetQuickstartsOptions{
Options: Options{
CommonOptions: commonOpts,
},
}
cmd := &cobra.Command{
Use: "quickstarts [flags]",
Short: "Lists the available quickstarts",
Long: getQuickstartsLong,
Example: getQuickstartsExample,
Aliases: []string{"quickstart", "qs"},
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
helper.CheckErr(err)
},
}
cmd.Flags().StringArrayVarP(&options.GitHubOrganisations, "organisations", "g", []string{}, "The GitHub organisations to query for quickstarts")
cmd.Flags().StringArrayVarP(&options.Filter.Tags, "tag", "t", []string{}, "The tags on the quickstarts to filter")
cmd.Flags().StringVarP(&options.Filter.Text, "filter", "f", "", "The text filter")
cmd.Flags().StringVarP(&options.Filter.Owner, "owner", "", "", "The owner to filter on")
cmd.Flags().StringVarP(&options.Filter.Language, "language", "l", "", "The language to filter on")
cmd.Flags().StringVarP(&options.Filter.Framework, "framework", "", "", "The framework to filter on")
cmd.Flags().BoolVarP(&options.Filter.AllowML, "machine-learning", "", false, "Allow machine-learning quickstarts in results")
cmd.Flags().BoolVarP(&options.ShortFormat, "short", "s", false, "return minimal details")
cmd.Flags().BoolVarP(&options.IgnoreTeam, "ignore-team", "", false, "ignores the quickstarts added to the Team Settings")
return cmd
}
// Run implements this command
func (o *GetQuickstartsOptions) Run() error {
model, err := o.LoadQuickStartsModel(o.GitHubOrganisations, o.IgnoreTeam)
if err != nil {
return fmt.Errorf("failed to load quickstarts: %s", err)
}
//output list of available quickstarts and exit
filteredQuickstarts := model.Filter(&o.Filter)
table := o.CreateTable()
if o.ShortFormat {
table.AddRow("NAME")
} else {
table.AddRow("NAME", "OWNER", "VERSION", "LANGUAGE", "URL")
}
for _, qs := range filteredQuickstarts {
if o.ShortFormat {
table.AddRow(qs.Name)
} else {
table.AddRow(qs.Name, qs.Owner, qs.Version, qs.Language, qs.DownloadZipURL)
}
}
table.Render()
return nil
}