Skip to content

Commit 59a6052

Browse files
committed
some fix
1 parent efcf545 commit 59a6052

3 files changed

Lines changed: 95 additions & 3 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ setup: deps devtools ## Set up dev env
2222
generate-mocks: ## Generate mock objects
2323
@echo "==> Generating mock objects"
2424
go install github.com/vektra/mockery/v2@v2.53.5
25-
mockery --name TiDBCloudClient --recursive --output=internal/mock --outpkg mock --filename api_client.go
26-
mockery --name EventsSender --recursive --output=internal/mock --outpkg mock --filename sender.go
27-
mockery --name Uploader --recursive --output=internal/mock --outpkg mock --filename uploader.go
25+
mockery --name TiDBCloudClient --recursive --dir=internal/service/cloud --output=internal/mock --outpkg mock --filename api_client.go
26+
mockery --name EventsSender --recursive --dir=internal/telemetry --output=internal/mock --outpkg mock --filename sender.go
27+
mockery --name Uploader --recursive --dir=internal/service/aws/s3 --output=internal/mock --outpkg mock --filename uploader.go
2828

2929
.PHONY: addcopy
3030
addcopy: ## Add copyright to all files

internal/flag/flag.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package flag
1616

1717
const (
18+
ExampleID string = "example-id"
1819
ClusterID string = "cluster-id"
1920
ClusterIDShort string = "c"
2021
LocalConcurrency string = "local.concurrency"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2026 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package ui
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/charmbracelet/bubbles/textinput"
21+
tea "github.com/charmbracelet/bubbletea"
22+
"github.com/juju/errors"
23+
"github.com/tidbcloud/tidbcloud-cli/internal/config"
24+
"github.com/tidbcloud/tidbcloud-cli/internal/util"
25+
)
26+
27+
type TextOneInputModel struct {
28+
Prompt string
29+
Input textinput.Model
30+
Err error
31+
Interrupted bool
32+
}
33+
34+
func (m TextOneInputModel) Init() tea.Cmd {
35+
return textinput.Blink
36+
}
37+
38+
func (m TextOneInputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
39+
var cmd tea.Cmd
40+
41+
switch msg := msg.(type) {
42+
case tea.KeyMsg:
43+
switch msg.Type {
44+
case tea.KeyEnter:
45+
return m, tea.Quit
46+
case tea.KeyCtrlC, tea.KeyEsc:
47+
m.Interrupted = true
48+
return m, tea.Quit
49+
}
50+
51+
case errMsg:
52+
m.Err = msg
53+
return m, nil
54+
}
55+
56+
m.Input, cmd = m.Input.Update(msg)
57+
return m, cmd
58+
}
59+
60+
func (m TextOneInputModel) View() string {
61+
return fmt.Sprintf(
62+
"%s\n\n%s\n\n%s\n\n",
63+
m.Prompt,
64+
m.Input.View(),
65+
helpMessageStyle("Press Enter to submit (esc to quit)"),
66+
)
67+
}
68+
69+
// InitialOneInputModel runs an interactive single-line input and returns the model and any error.
70+
// view is the prompt line shown above the input. placeholder is used as the input placeholder text.
71+
func InitialOneInputModel(prompt, placeholder string) (TextOneInputModel, error) {
72+
ti := textinput.New()
73+
ti.Placeholder = placeholder
74+
ti.Focus()
75+
ti.PromptStyle = config.FocusedStyle
76+
ti.TextStyle = config.FocusedStyle
77+
78+
p := tea.NewProgram(TextOneInputModel{Prompt: prompt, Input: ti})
79+
model, err := p.Run()
80+
finalModel := model.(TextOneInputModel)
81+
if err != nil {
82+
return finalModel, errors.Trace(err)
83+
}
84+
if finalModel.Interrupted {
85+
return finalModel, util.InterruptError
86+
}
87+
if finalModel.Err != nil {
88+
return finalModel, finalModel.Err
89+
}
90+
return finalModel, nil
91+
}

0 commit comments

Comments
 (0)