From 31ebd4ed91c7106758fa928a2c1a294f0e096792 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 28 Oct 2024 11:30:52 -0500 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=9B=A0=20Add=20.gitignore=20to=20buil?= =?UTF-8?q?d=20directory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - build/.gitignore | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 build/.gitignore diff --git a/.gitignore b/.gitignore index c525b60..f1c37ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -build/ .task/ diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From 36ad4b260ec1f227dabca7287c19334c5394a6ba Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 28 Oct 2024 20:01:03 -0500 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=9B=A0=20Add=20static=20analysis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Taskfile.yml | 26 ++++++++++++++++++++++++++ cli/spin/spin.go | 7 ++++--- convids/methods.go | 7 ++----- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 77b972d..8be3d99 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -9,6 +9,32 @@ tasks: - "**/*.go" cmds: - go fmt ./... + + vet: + desc: Vet go code + sources: + - '**/*.go' + cmds: + - go vet ./... + critic: + desc: Critique go code + sources: + - '**/*.go' + cmds: + - gocritic check ./... + staticcheck: + desc: Static check go code + sources: + - '**/*.go' + cmds: + - staticcheck ./... + analyze: + desc: Do static analysis + deps: + - vet + - critic + - staticcheck + cmd-build: internal: true cmds: diff --git a/cli/spin/spin.go b/cli/spin/spin.go index 2896335..3d0a804 100644 --- a/cli/spin/spin.go +++ b/cli/spin/spin.go @@ -82,11 +82,12 @@ func (s *spin) SetMessage(msg string) { } func (s *spin) Err() error { - if errors.Is(s.err, context.Canceled) { + switch { + case errors.Is(s.err, context.Canceled): return nil - } else if errors.Is(s.err, context.DeadlineExceeded) { + case errors.Is(s.err, context.DeadlineExceeded): return nil - } else if errors.Is(s.err, tea.ErrProgramKilled) { + case errors.Is(s.err, tea.ErrProgramKilled): return nil } return s.err diff --git a/convids/methods.go b/convids/methods.go index 69ce198..8162848 100644 --- a/convids/methods.go +++ b/convids/methods.go @@ -38,10 +38,7 @@ func (s *Show) matchRegexp(path string) (f bool, err error) { if s.re == nil { p := s.Pattern if s.Anime { - if strings.HasPrefix(p, "^") { - p = strings.TrimPrefix(p, "^") - } - p = animePattern + p + p = animePattern + strings.TrimPrefix(p, "^") } else if !strings.HasPrefix(p, "^") { p = "^" + p } @@ -71,7 +68,7 @@ func (d *Data) AllShows(silent bool) iter.Seq[*Show] { continue } if !silent { - fmt.Println("Checking", show, "shows\n") + fmt.Printf("Checking %s shows\n\n", show) } for s := range sh.All() { if s == nil { From f7fca3ba7351a869e21119149981fc7aa886f6f4 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 28 Oct 2024 20:07:19 -0500 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=9B=A0=20Add=20default=20task?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Taskfile.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Taskfile.yml b/Taskfile.yml index 8be3d99..1fa4827 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -3,6 +3,13 @@ version: '3' tasks: + default: + desc: fmt, vet, and build + deps: + - fmt + - analyze + - build-all + fmt: desc: Format go files sources: From fd68ffbbf8ee90d74a992757a76ff74e6047f7d6 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Tue, 29 Oct 2024 11:28:47 -0500 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=90=9B=20Program=20should=20still=20h?= =?UTF-8?q?alt=20even=20with=20spinner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/context/signal.go | 21 +++++++++++++++++++++ cli/spin/spin.go | 7 ++++++- cmd/cool-down/main.go | 5 ++++- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 cli/context/signal.go diff --git a/cli/context/signal.go b/cli/context/signal.go new file mode 100644 index 0000000..cf8f620 --- /dev/null +++ b/cli/context/signal.go @@ -0,0 +1,21 @@ +package context + +import ( + "context" + "os" + "os/signal" + "syscall" +) + +func SelfCancelingCotext(ctx context.Context) (context.Context, context.CancelFunc) { + c, done := context.WithCancel(ctx) + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) + go func() { + for range ch { + done() + } + }() + + return c, done +} diff --git a/cli/spin/spin.go b/cli/spin/spin.go index 3d0a804..d5570fa 100644 --- a/cli/spin/spin.go +++ b/cli/spin/spin.go @@ -94,7 +94,12 @@ func (s *spin) Err() error { } func Spin(ctx context.Context, message string) Spinner { - p := tea.NewProgram(newModel(message), tea.WithContext(ctx)) + p := tea.NewProgram( + newModel(message), + tea.WithContext(ctx), + tea.WithoutSignalHandler(), + tea.WithInput(nil), + ) s := &spin{p: p, finished: make(chan struct{}, 1)} go func() { _, err := s.p.Run() diff --git a/cmd/cool-down/main.go b/cmd/cool-down/main.go index 18487b1..234a06a 100644 --- a/cmd/cool-down/main.go +++ b/cmd/cool-down/main.go @@ -4,12 +4,15 @@ import ( "context" "codeberg.org/danjones000/utils/chill" + c "codeberg.org/danjones000/utils/cli/context" e "codeberg.org/danjones000/utils/cli/err" "codeberg.org/danjones000/utils/cli/spin" ) func main() { - ctx := chill.Chill(context.Background()) + ctx, done := c.SelfCancelingCotext(context.Background()) + defer done() + ctx = chill.Chill(ctx) s := spin.Spin(ctx, "Waiting for CPU to cool...") err := s.Wait() e.HandleErr(err) From f41ac8575ffe319a67c2c97683b974c5df0ffa6a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 1 Nov 2024 12:09:50 -0500 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=9A=80=20Add=20install-cool-down=20bu?= =?UTF-8?q?ild=20target?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cool-down seems stable now --- Taskfile.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Taskfile.yml b/Taskfile.yml index 1fa4827..34dfb3f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -2,6 +2,13 @@ version: '3' +vars: + GOBIN_ENV: + sh: go env GOBIN + GOPATH_ENV: + sh: go env GOPATH + BIN: '{{if .GOBIN_ENV}}{{.GOBIN_ENV}}{{else}}{{.GOPATH_ENV}}/bin{{end}}' + tasks: default: desc: fmt, vet, and build @@ -82,3 +89,18 @@ tasks: - task: cmd-build vars: CMD: "*" + + install-cool-down: + desc: Installs the cool-down command + source: + - cmd/cool-down/**/*.go + - chill/*.go + - cli/context/*.go + - cli/err/*.go + - cli/spin/*.go + - go.mod + - go.sum + generates: + - '{{.BIN}}/cool-down' + cmds: + - go install ./cmd/cool-down