@@ -39,23 +39,31 @@ var lintCommand = cli.Command{
3939 Usage : "Watch for files to change and re-run linting" ,
4040 },
4141 },
42- Action : runLinter ,
42+ Action : func (ctx context.Context , cmd * cli.Command ) error {
43+ if cmd .Bool ("watch" ) {
44+ // Clear the screen and move the cursor to the top
45+ fmt .Print ("\033 [2J\033 [H" )
46+ os .Stdout .Sync ()
47+ }
48+ return runLinter (ctx , cmd , false )
49+ },
4350}
4451
4552var helpStyle = lipgloss .NewStyle ().
4653 Foreground (lipgloss .Color ("241" )).
4754 Margin (1 , 0 , 0 , 0 )
4855
4956type lintModel struct {
50- spinner spinner.Model
51- diagnostics []stainless.BuildDiagnostic
52- error error
53- watching bool
54- ctx context.Context
55- cmd * cli.Command
56- cc * apiCommandContext
57- stopPolling chan struct {}
58- help helpModel
57+ spinner spinner.Model
58+ diagnostics []stainless.BuildDiagnostic
59+ error error
60+ watching bool
61+ stopWhenPassing bool
62+ ctx context.Context
63+ cmd * cli.Command
64+ cc * apiCommandContext
65+ stopPolling chan struct {}
66+ help helpModel
5967}
6068
6169type helpModel struct {
@@ -64,18 +72,17 @@ type helpModel struct {
6472}
6573
6674func (m lintModel ) Init () tea.Cmd {
67- if m .watching {
68- // Clear the screen and move the cursor to the top
69- fmt .Print ("\033 [2J\033 [H" )
70- os .Stdout .Sync ()
71- }
7275 return m .spinner .Tick
7376}
7477
7578func (m lintModel ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
7679 switch msg := msg .(type ) {
7780 case tea.KeyMsg :
7881 if msg .String () == "ctrl+c" {
82+ m .watching = false
83+ m .error = ErrUserCancelled
84+ return m , tea .Quit
85+ } else if msg .String () == "enter" {
7986 m .watching = false
8087 return m , tea .Quit
8188 }
@@ -87,6 +94,11 @@ func (m lintModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8794 m .cmd = msg .cmd
8895 m .cc = msg .cc
8996
97+ if m .stopWhenPassing && ! hasBlockingDiagnostic (m .diagnostics ) {
98+ m .watching = false
99+ return m , tea .Quit
100+ }
101+
90102 if m .watching {
91103 return m , func () tea.Msg {
92104 if err := waitTillConfigChanges (m .ctx , m .cmd , m .cc ); err != nil {
@@ -130,8 +142,13 @@ func (m lintModel) View() string {
130142 }
131143 }
132144
133- helpText := helpStyle .Render ("Press Ctrl+C to exit" )
134- return content + helpText
145+ if m .stopWhenPassing {
146+ content += helpStyle .Render ("Press Enter to skip diagnostics, Ctrl+C to exit" )
147+ } else {
148+ content += helpStyle .Render ("Press Ctrl+C to exit" )
149+ }
150+
151+ return content
135152}
136153
137154type diagnosticsMsg struct {
@@ -155,21 +172,22 @@ func getDiagnosticsCmd(ctx context.Context, cmd *cli.Command, cc *apiCommandCont
155172 }
156173}
157174
158- func runLinter (ctx context.Context , cmd * cli.Command ) error {
175+ func runLinter (ctx context.Context , cmd * cli.Command , stopWhenPassing bool ) error {
159176 cc := getAPICommandContext (cmd )
160177
161178 s := spinner .New ()
162179 s .Spinner = spinner .MiniDot
163180 s .Style = lipgloss .NewStyle ().Foreground (lipgloss .Color ("208" ))
164181
165182 m := lintModel {
166- spinner : s ,
167- watching : cmd .Bool ("watch" ),
168- ctx : ctx ,
169- cmd : cmd ,
170- cc : cc ,
171- stopPolling : make (chan struct {}),
172- help : helpModel {},
183+ spinner : s ,
184+ watching : cmd .Bool ("watch" ),
185+ stopWhenPassing : stopWhenPassing ,
186+ ctx : ctx ,
187+ cmd : cmd ,
188+ cc : cc ,
189+ stopPolling : make (chan struct {}),
190+ help : helpModel {},
173191 }
174192
175193 p := tea .NewProgram (m , tea .WithContext (ctx ))
0 commit comments