Skip to content

Commit

Permalink
added gen team set command
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerMizuyabu committed Aug 9, 2024
1 parent d91c916 commit e296792
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gen

import (
repositoryset "gh_foundations/cmd/gen/repository_set"
teamset "gh_foundations/cmd/gen/team_set"

"github.com/spf13/cobra"
)
Expand All @@ -14,4 +15,5 @@ var GenCmd = &cobra.Command{

func init() {
GenCmd.AddCommand(repositoryset.GenRepositorySetCmd)
GenCmd.AddCommand(teamset.GenTeamSetCmd)
}
72 changes: 72 additions & 0 deletions cmd/gen/team_set/interactive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package teamset

import (
"fmt"
"gh_foundations/cmd/gen/common"
githubfoundations "gh_foundations/internal/pkg/types/github_foundations"
"os"

tea "github.com/charmbracelet/bubbletea"
yaml "gopkg.in/yaml.v2"
)

var questions []common.IQuestion = []common.IQuestion{
common.NewTextQuestion(
"Enter the name of the team",
"",
),
common.NewTextQuestion(
"Enter the description for the team",
"",
),
common.NewSelectQuestion(
"Select the level of privacy for the team",
[]string{
"secret",
"closed",
},
),
common.NewListQuestion(
"Enter the team maintainers",
),
common.NewListQuestion(
"Enter the team members",
),
common.NewTextQuestion(
"Enter the id of the parent team if any",
"",
),
}

func submitFunc(answers []string, teamSet *githubfoundations.TeamSetInput) {
team := new(githubfoundations.TeamInput)
team.Name = answers[0]
team.Description = answers[1]
team.Privacy = answers[2]
maintainers := make([]string, 0)
err := yaml.Unmarshal([]byte(answers[3]), &maintainers)
if err != nil {
fmt.Println("Error converting maintainers input to array of strings:", err)
os.Exit(1)
}
team.Maintainers = maintainers

members := make([]string, 0)
err = yaml.Unmarshal([]byte(answers[4]), &members)
if err != nil {
fmt.Println("Error converting members input to array of strings:", err)
os.Exit(1)
}
team.Members = members

team.ParentId = answers[5]
teamSet.Teams = append(teamSet.Teams, team)
}

func runInteractive() (*githubfoundations.TeamSetInput, error) {
m := common.NewModel(questions, new(githubfoundations.TeamSetInput), submitFunc)
if _, err := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion()).Run(); err != nil {
return nil, err
}
return m.Result, nil
}
34 changes: 34 additions & 0 deletions cmd/gen/team_set/team_set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package teamset

import (
"fmt"
"os"

"gh_foundations/cmd/gen/common"
githubfoundations "gh_foundations/internal/pkg/types/github_foundations"

zone "github.com/lrstanley/bubblezone"
"github.com/spf13/cobra"
)

var GenTeamSetCmd = &cobra.Command{
Use: "team_set",
Short: "Generates an hcl file that contains a team set input. Can only be run interactively.",
Long: `Generates an hcl file that contains a team set input. Can only be run interactively.`,
Run: func(cmd *cobra.Command, args []string) {
zone.NewGlobal()
var teamSet *githubfoundations.TeamSetInput
var err error

teamSet, err = runInteractive()
if err != nil {
fmt.Println("Error running interactive mode:", err)
os.Exit(1)
}

if err := common.OutputHCLToFile("team_set.inputs.hcl", teamSet); err != nil {
fmt.Println("Error writing hcl file:", err)
os.Exit(1)
}
},
}

0 comments on commit e296792

Please sign in to comment.