diff --git a/tui/cmd/alt/.deploystack/deploystack.yaml b/tui/cmd/alt/.deploystack/deploystack.yaml new file mode 100644 index 0000000..918834a --- /dev/null +++ b/tui/cmd/alt/.deploystack/deploystack.yaml @@ -0,0 +1,50 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +title: "Three Tier App (TODO)" +name: "practice_application" +duration: 9 +documentation_link: "https://cloud.google.com/shell/docs/cloud-shell-tutorials/deploystack/three-tier-app" +collect_project: true +collect_project_number: true +collect_region: true +collect_billing_account: false +region_type: "run" +region_default: "us-central1" +collect_zone: true +# You can even include comments in this yaml +hard_settings: + basename: "three-tier-app" +custom_settings: + - name : "roles" + description: "Please enter the role" + default : "roles/owner|Project Owner" + options : + - "roles/reviewer|Project Reviewer" + - "roles/owner|Project Owner" + - "roles/vison.reader|Cloud Vision Reader" + - name : "roles" + description: "Please enter the number of nodes" + default : "3" +products : + - info: "VM template" + product: "Instance Template" + - info: "Clustering" + product: "Managed Instance Group" + - info: "Load Balancing" + product: "Load Balancer" +description: | + This is additional stuff that will go here and be formatted. + * You can add a bullet list + * That's totally cool diff --git a/tui/cmd/alt/main.go b/tui/cmd/alt/main.go new file mode 100644 index 0000000..878e652 --- /dev/null +++ b/tui/cmd/alt/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "github.com/GoogleCloudPlatform/deploystack" + "github.com/GoogleCloudPlatform/deploystack/tui" +) + +func main() { + + s, err := deploystack.Init() + if err != nil { + tui.Fatal(err) + } + + tui.AltRun(s, true) +} diff --git a/tui/mainpage.go b/tui/mainpage.go new file mode 100644 index 0000000..dc8bbea --- /dev/null +++ b/tui/mainpage.go @@ -0,0 +1,124 @@ +package tui + +import ( + "context" + "fmt" + "os" + "strings" + + "github.com/GoogleCloudPlatform/deploystack" + "github.com/GoogleCloudPlatform/deploystack/config" + "github.com/GoogleCloudPlatform/deploystack/gcloud" + tea "github.com/charmbracelet/bubbletea" +) + +type model interface { + tea.Model + getKey() string + setValue(s string) + getValue() string + clear() + clearContent() + addPostProcessor(f func(string, *Queue) tea.Cmd) + addPreProcessor(f tea.Cmd) + addQueue(q *Queue) + addContent(s ...string) + addPreView(f func(*Queue)) +} + +type mainpage struct { + header component + queue *Queue + currentPage *model +} + +func newMainPage(h header, q *Queue) mainpage { + return mainpage{header: h, queue: q} +} + +func (m mainpage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + mod := *m.currentPage + return mod.Update(msg) +} + +func (m mainpage) View() string { + mod := *m.currentPage + doc := strings.Builder{} + + doc.WriteString(m.header.render()) + doc.WriteString(mod.View()) + + return docStyle.Render(doc.String()) +} + +func (m mainpage) Init() tea.Cmd { + if m.currentPage == nil { + curr := m.queue.Start().(model) + + m.currentPage = &curr + } + + mod := *m.currentPage + return mod.Init() +} + +func AltRun(s *config.Stack, useMock bool) { + if len(os.Getenv("DEBUG")) > 0 { + f, err := tea.LogToFile("debug.log", "debug") + if err != nil { + fmt.Println("fatal:", err) + os.Exit(1) + } + defer f.Close() + } + + defaultUserAgent := fmt.Sprintf("deploystack/%s", s.Config.Name) + + client := gcloud.NewClient(context.Background(), defaultUserAgent) + q := NewQueue(s, &client) + + if useMock { + q = NewQueue(s, GetMock(1)) + } + + // q.Save("contact", deploystack.CheckForContact()) + // q.InitializeUI() + desc := newDescription(q.stack) + appHeader := newHeader(appTitle, q.stack.Config.Title) + firstPage := newPage("firstpage", []component{newTextBlock(explainText)}) + descPage := newPage("descpage", []component{desc}) + firstPage.showProgress = false + descPage.showProgress = false + endpage := newPage("endpage", []component{ + newTextBlock(titleStyle.Render("Project Settings")), + newSettingsTable(q.stack), + }) + + q.header = appHeader + q.add(&firstPage) + q.add(&descPage) + q.ProcessConfig() + q.add(&endpage) + + m := newMainPage(appHeader, &q) + + p := tea.NewProgram(m, tea.WithAltScreen()) + if _, err := p.Run(); err != nil { + Fatal(err) + } + + if q.Get("halted") != nil { + Fatal(nil) + } + + s.TerraformFile("terraform.tfvars") + deploystack.CacheContact(q.Get("contact")) + + fmt.Print("\n\n") + fmt.Print(titleStyle.Render("Deploystack")) + fmt.Print("\n") + fmt.Print(subTitleStyle.Render(s.Config.Title)) + fmt.Print("\n") + fmt.Print(strong.Render("Installation will proceed with these settings")) + fmt.Print(q.getSettings()) +}