mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
package tdbg
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
type (
|
|
// Prompter is a helper for prompting the user for confirmation.
|
|
Prompter struct {
|
|
writer io.Writer
|
|
reader io.Reader
|
|
exiter func(code int)
|
|
flagLookup BoolFlagLookup
|
|
}
|
|
// PrompterParams is used to configure a new Prompter.
|
|
PrompterParams struct {
|
|
// Reader defaults to os.Stdin.
|
|
Reader io.Reader
|
|
// Writer defaults to os.Stdout.
|
|
Writer io.Writer
|
|
// Exiter defaults to [os.Exit].
|
|
Exiter func(code int)
|
|
}
|
|
// PrompterOption is used to override default PrompterParams.
|
|
PrompterOption func(*PrompterParams)
|
|
// BoolFlagLookup can be satisfied by [github.com/urfave/cli/v2.Context].
|
|
BoolFlagLookup interface {
|
|
Bool(name string) bool
|
|
}
|
|
PrompterFactory func(c BoolFlagLookup) *Prompter
|
|
)
|
|
|
|
func NewPrompterFactory(opts ...PrompterOption) PrompterFactory {
|
|
return func(c BoolFlagLookup) *Prompter {
|
|
return NewPrompter(c, opts...)
|
|
}
|
|
}
|
|
|
|
// NewPrompter creates a new Prompter. In most cases, the first argument should be [github.com/urfave/cli/v2.Context].
|
|
func NewPrompter(c BoolFlagLookup, opts ...PrompterOption) *Prompter {
|
|
params := PrompterParams{
|
|
Writer: os.Stdout,
|
|
Reader: os.Stdin,
|
|
Exiter: os.Exit,
|
|
}
|
|
for _, opt := range opts {
|
|
opt(¶ms)
|
|
}
|
|
return &Prompter{
|
|
writer: params.Writer,
|
|
reader: params.Reader,
|
|
exiter: params.Exiter,
|
|
flagLookup: c,
|
|
}
|
|
}
|
|
|
|
// Prompt the user for confirmation. If the user does not respond with "y" or "yes" (case-insensitive and without
|
|
// leading or trailing space), the process will exit with code 1.
|
|
func (p *Prompter) Prompt(msg string) {
|
|
if p.flagLookup.Bool(FlagYes) {
|
|
return
|
|
}
|
|
_, err := p.writer.Write([]byte(msg + " [y/N]: "))
|
|
if err != nil {
|
|
panic(fmt.Errorf("failed to write prompt: %w", err))
|
|
}
|
|
reader := bufio.NewReader(p.reader)
|
|
text, err := reader.ReadString('\n')
|
|
if err != nil {
|
|
panic(fmt.Errorf("failed to read prompt: %w", err))
|
|
}
|
|
textLower := strings.ToLower(strings.TrimSpace(text))
|
|
if textLower != "y" && textLower != "yes" {
|
|
p.exiter(1)
|
|
}
|
|
}
|