-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d91c916
commit e296792
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}, | ||
} |