Compare commits
No commits in common. "f41ac8575ffe319a67c2c97683b974c5df0ffa6a" and "2d70d8994ef9caec7f5364621a5785a910b8977d" have entirely different histories.
f41ac8575f
...
2d70d8994e
7 changed files with 11 additions and 94 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
|
build/
|
||||||
.task/
|
.task/
|
||||||
|
|
|
||||||
55
Taskfile.yml
55
Taskfile.yml
|
|
@ -2,53 +2,13 @@
|
||||||
|
|
||||||
version: '3'
|
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:
|
tasks:
|
||||||
default:
|
|
||||||
desc: fmt, vet, and build
|
|
||||||
deps:
|
|
||||||
- fmt
|
|
||||||
- analyze
|
|
||||||
- build-all
|
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
desc: Format go files
|
desc: Format go files
|
||||||
sources:
|
sources:
|
||||||
- "**/*.go"
|
- "**/*.go"
|
||||||
cmds:
|
cmds:
|
||||||
- go fmt ./...
|
- 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:
|
cmd-build:
|
||||||
internal: true
|
internal: true
|
||||||
cmds:
|
cmds:
|
||||||
|
|
@ -89,18 +49,3 @@ tasks:
|
||||||
- task: cmd-build
|
- task: cmd-build
|
||||||
vars:
|
vars:
|
||||||
CMD: "*"
|
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
|
|
||||||
|
|
|
||||||
2
build/.gitignore
vendored
2
build/.gitignore
vendored
|
|
@ -1,2 +0,0 @@
|
||||||
*
|
|
||||||
!.gitignore
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
@ -82,24 +82,18 @@ func (s *spin) SetMessage(msg string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *spin) Err() error {
|
func (s *spin) Err() error {
|
||||||
switch {
|
if errors.Is(s.err, context.Canceled) {
|
||||||
case errors.Is(s.err, context.Canceled):
|
|
||||||
return nil
|
return nil
|
||||||
case errors.Is(s.err, context.DeadlineExceeded):
|
} else if errors.Is(s.err, context.DeadlineExceeded) {
|
||||||
return nil
|
return nil
|
||||||
case errors.Is(s.err, tea.ErrProgramKilled):
|
} else if errors.Is(s.err, tea.ErrProgramKilled) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return s.err
|
return s.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Spin(ctx context.Context, message string) Spinner {
|
func Spin(ctx context.Context, message string) Spinner {
|
||||||
p := tea.NewProgram(
|
p := tea.NewProgram(newModel(message), tea.WithContext(ctx))
|
||||||
newModel(message),
|
|
||||||
tea.WithContext(ctx),
|
|
||||||
tea.WithoutSignalHandler(),
|
|
||||||
tea.WithInput(nil),
|
|
||||||
)
|
|
||||||
s := &spin{p: p, finished: make(chan struct{}, 1)}
|
s := &spin{p: p, finished: make(chan struct{}, 1)}
|
||||||
go func() {
|
go func() {
|
||||||
_, err := s.p.Run()
|
_, err := s.p.Run()
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,12 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"codeberg.org/danjones000/utils/chill"
|
"codeberg.org/danjones000/utils/chill"
|
||||||
c "codeberg.org/danjones000/utils/cli/context"
|
|
||||||
e "codeberg.org/danjones000/utils/cli/err"
|
e "codeberg.org/danjones000/utils/cli/err"
|
||||||
"codeberg.org/danjones000/utils/cli/spin"
|
"codeberg.org/danjones000/utils/cli/spin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, done := c.SelfCancelingCotext(context.Background())
|
ctx := chill.Chill(context.Background())
|
||||||
defer done()
|
|
||||||
ctx = chill.Chill(ctx)
|
|
||||||
s := spin.Spin(ctx, "Waiting for CPU to cool...")
|
s := spin.Spin(ctx, "Waiting for CPU to cool...")
|
||||||
err := s.Wait()
|
err := s.Wait()
|
||||||
e.HandleErr(err)
|
e.HandleErr(err)
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,10 @@ func (s *Show) matchRegexp(path string) (f bool, err error) {
|
||||||
if s.re == nil {
|
if s.re == nil {
|
||||||
p := s.Pattern
|
p := s.Pattern
|
||||||
if s.Anime {
|
if s.Anime {
|
||||||
p = animePattern + strings.TrimPrefix(p, "^")
|
if strings.HasPrefix(p, "^") {
|
||||||
|
p = strings.TrimPrefix(p, "^")
|
||||||
|
}
|
||||||
|
p = animePattern + p
|
||||||
} else if !strings.HasPrefix(p, "^") {
|
} else if !strings.HasPrefix(p, "^") {
|
||||||
p = "^" + p
|
p = "^" + p
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +71,7 @@ func (d *Data) AllShows(silent bool) iter.Seq[*Show] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !silent {
|
if !silent {
|
||||||
fmt.Printf("Checking %s shows\n\n", show)
|
fmt.Println("Checking", show, "shows\n")
|
||||||
}
|
}
|
||||||
for s := range sh.All() {
|
for s := range sh.All() {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue