Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag support to bundle new #30

Merged
merged 35 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d6c874c
Add flag support to bundle new
mclacore Apr 8, 2023
6c6d8a0
Refactoring to split bundle new function
mclacore Apr 15, 2023
45d7182
Merge branch 'main' into michael/bundle-new-flags
mclacore May 20, 2023
79ab04c
Revert "Add flag support to bundle new"
mclacore May 20, 2023
aab6597
Reverses name/artifact pairing
mclacore May 20, 2023
e6e45a6
Fixing init method for args
mclacore May 20, 2023
e41d048
Merge branch 'main' into michael/bundle-new-flags
mclacore Sep 8, 2023
57d76b6
Refactoring for cleanup
mclacore Sep 11, 2023
65ca751
Add flag support to bundle new
mclacore Apr 8, 2023
4ef37fc
Refactoring to split bundle new function
mclacore Apr 15, 2023
dbc840d
Revert "Add flag support to bundle new"
mclacore May 20, 2023
99460c6
Reverses name/artifact pairing
mclacore May 20, 2023
2445aee
Fixing init method for args
mclacore May 20, 2023
4c0974a
Refactoring for cleanup
mclacore Sep 11, 2023
f30138e
Merge branch 'michael/bundle-new-flags' of github.com:massdriver-clou…
mclacore Sep 14, 2023
39af216
Add flag support to bundle new
mclacore Apr 8, 2023
068463b
Refactoring to split bundle new function
mclacore Apr 15, 2023
7dba1f6
Revert "Add flag support to bundle new"
mclacore May 20, 2023
5af0992
Reverses name/artifact pairing
mclacore May 20, 2023
66c1d1b
Fixing init method for args
mclacore May 20, 2023
7f10ce3
Refactoring for cleanup
mclacore Sep 11, 2023
d7949df
Add flag support to bundle new
mclacore Apr 8, 2023
be0d39f
Refactoring to split bundle new function
mclacore Apr 15, 2023
a941975
Revert "Add flag support to bundle new"
mclacore May 20, 2023
eef726e
Reverses name/artifact pairing
mclacore May 20, 2023
efe33d8
Fixing init method for args
mclacore May 20, 2023
9192230
Refactoring for cleanup
mclacore Sep 11, 2023
c5ecf54
Merge branch 'main' into michael/bundle-new-flags
mclacore Dec 18, 2023
1874a5c
Merge branch 'michael/bundle-new-flags' of github.com:massdriver-clou…
mclacore Dec 18, 2023
27199d8
Manual rebase since auto rebase broke
mclacore Dec 18, 2023
2c6d77f
Refactoring from rebase
mclacore Dec 18, 2023
e56faf0
Mass docs
mclacore Dec 18, 2023
248a938
Lint whitespace
mclacore Dec 18, 2023
37a449c
Fix lint issues
mclacore Dec 18, 2023
fb07573
Fixing more lint issues
mclacore Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 120 additions & 12 deletions cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ func NewCmdBundle() *cobra.Command {
bundleCmd.AddCommand(bundleTemplateCmd)
bundleTemplateCmd.AddCommand(bundleTemplateListCmd)
bundleTemplateCmd.AddCommand(bundleTemplateRefreshCmd)

bundleNewCmd.Flags().StringP("name", "n", "", "Name of the new bundle")
bundleNewCmd.Flags().StringP("description", "d", "", "Description of the new bundle")
bundleNewCmd.Flags().StringP("template-type", "t", "", "Name of the bundle template to use")
bundleNewCmd.Flags().StringSliceP("connections", "c", []string{}, "Connections and names to add to the bundle - example: massdriver/vpc=network")
mclacore marked this conversation as resolved.
Show resolved Hide resolved
bundleNewCmd.Flags().StringP("output-directory", "o", ".", "Directory to output the new bundle")
return bundleCmd
}

Expand Down Expand Up @@ -117,14 +121,113 @@ func runBundleTemplateRefresh(cmd *cobra.Command, args []string) error {
return commands.RefreshTemplates(cache)
}

func runBundleNewInteractive(outputDir string) (*templatecache.TemplateData, error) {
templateData := &templatecache.TemplateData{
Access: "private",
// Promptui templates are a nightmare. Need to support multi repos when moving this to bubbletea
TemplateRepo: "/massdriver-cloud/application-templates",
// TODO: unify bundle build and app build outputDir logic and support
OutputDir: outputDir,
}

err := bundle.RunPromptNew(templateData)
if err != nil {
return nil, err
}

return templateData, nil
}

func runBundleNewFlags(cmd *cobra.Command) (*templatecache.TemplateData, error) {
name, err := cmd.Flags().GetString("name")
if err != nil {
return nil, err
}

description, err := cmd.Flags().GetString("description")
if err != nil {
return nil, err
}

connections, err := cmd.Flags().GetStringSlice("connections")
if err != nil {
return nil, err
}

templateName, err := cmd.Flags().GetString("template-type")
if err != nil {
return nil, err
}

outputDir, err := cmd.Flags().GetString("output-directory")
if err != nil {
return nil, err
}

connectionData := make([]templatecache.Connection, len(connections))
for i, conn := range connections {
parts := strings.Split(conn, "=")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid connection argument: %s", conn)
}
connectionData[i] = templatecache.Connection{
ArtifactDefinition: parts[1],
Name: parts[0],
}
}

templateData := &templatecache.TemplateData{
Access: "private",
TemplateRepo: "/massdriver-cloud/application-templates",
OutputDir: outputDir,
Name: name,
Description: description,
TemplateName: templateName,
Connections: connectionData,
}

return templateData, nil
}

func runBundleNew(cmd *cobra.Command, args []string) error {
var fs = afero.NewOsFs()
cache, _ := templatecache.NewBundleTemplateCache(templatecache.GithubTemplatesFetcher, fs)
err := commands.RefreshTemplates(cache)
fs := afero.NewOsFs()
cache, err := templatecache.NewBundleTemplateCache(templatecache.GithubTemplatesFetcher, fs)
if err != nil {
return err
}

err = commands.RefreshTemplates(cache)
if err != nil {
return err
}

var (
name string
templateName string
outputDir string
)

// define flag
name, err = cmd.Flags().GetString("name")
if err != nil {
return err
}

templateName, err = cmd.Flags().GetString("template-type")
if err != nil {
return err
}

outputDir, err = cmd.Flags().GetString("output-directory")
if err != nil {
return err
}

// parse flags
if err = cmd.ParseFlags(args); err != nil {
return err
}

c, configErr := config.Get()
if configErr != nil {
return configErr
Expand All @@ -148,15 +251,21 @@ func runBundleNew(cmd *cobra.Command, args []string) error {

bundle.SetMassdriverArtifactDefinitions(artifacts)

templateData := &templatecache.TemplateData{
Access: "private",
// Promptui templates are a nightmare. Need to support multi repos when moving this to bubbletea
TemplateRepo: "/massdriver-cloud/application-templates",
// TODO: unify bundle build and app build outputDir logic and support
OutputDir: ".",
var templateData *templatecache.TemplateData
if name == "" || templateName == "" {
// run the interactive prompt
templateData, err = runBundleNewInteractive(outputDir)
if err != nil {
return err
}
} else {
// skip the interactive prompt and use flags
templateData, err = runBundleNewFlags(cmd)
if err != nil {
return err
}
}

err = bundle.RunPromptNew(templateData)
if err != nil {
return err
}
Expand All @@ -165,7 +274,6 @@ func runBundleNew(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}

return nil
}

Expand Down
7 changes: 6 additions & 1 deletion docs/generated/mass_bundle_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ mass bundle new [flags]
### Options

```
-h, --help help for new
-c, --connections strings Connections and names to add to the bundle - example: massdriver/vpc=network
-d, --description string Description of the new bundle
-h, --help help for new
-n, --name string Name of the new bundle
-o, --output-directory string Directory to output the new bundle (default ".")
-t, --template-type string Name of the bundle template to use
```

### SEE ALSO
Expand Down
Loading