mirror of
https://github.com/charmbracelet/gum.git
synced 2024-08-17 02:00:46 +03:00
chore: fix linting
This commit is contained in:
parent
61a9219d0a
commit
cb590e324e
@ -55,7 +55,7 @@ const (
|
||||
ShellCompDirectiveFilterDirs
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
//
|
||||
// All directives using iota should be above this one.
|
||||
// For internal use.
|
||||
shellCompDirectiveMaxValue //nolint:deadcode,unused,varcheck
|
||||
|
@ -39,8 +39,7 @@ func isArgument(cmd *kong.Node) bool {
|
||||
|
||||
// writeString writes a string into a buffer, and checks if the error is not nil.
|
||||
func writeString(b io.StringWriter, s string) {
|
||||
_, err := b.WriteString(s)
|
||||
if err != nil {
|
||||
if _, err := b.WriteString(s); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -24,9 +24,8 @@ func (o Options) Run() error {
|
||||
i.Placeholder = o.Placeholder
|
||||
i.Width = o.Width
|
||||
|
||||
input, _ := stdin.Read()
|
||||
var choices []string
|
||||
if input != "" {
|
||||
if input, _ := stdin.Read(); input != "" {
|
||||
choices = strings.Split(strings.TrimSpace(input), "\n")
|
||||
} else {
|
||||
choices = files.List()
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
)
|
||||
|
||||
// Func is a function that formats some text
|
||||
// Func is a function that formats some text.
|
||||
type Func func(string) (string, error)
|
||||
|
||||
var formatType = map[string]Func{
|
||||
@ -28,7 +28,7 @@ var formatType = map[string]Func{
|
||||
"template": template,
|
||||
}
|
||||
|
||||
// Run runs the format command
|
||||
// Run runs the format command.
|
||||
func (o Options) Run() error {
|
||||
var input string
|
||||
if len(o.Template) > 0 {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package format
|
||||
|
||||
// Options is customization options for the format command
|
||||
// Options is customization options for the format command.
|
||||
type Options struct {
|
||||
Template []string `arg:"" optional:"" help:"Template string to format (can also be provided via stdin)"`
|
||||
|
||||
|
@ -14,11 +14,8 @@ import (
|
||||
// Run provides a shell script interface for the text input bubble.
|
||||
// https://github.com/charmbracelet/bubbles/textinput
|
||||
func (o Options) Run() error {
|
||||
in, _ := stdin.Read()
|
||||
|
||||
i := textinput.New()
|
||||
|
||||
if in != "" && o.Value == "" {
|
||||
if in, _ := stdin.Read(); in != "" && o.Value == "" {
|
||||
i.SetValue(in)
|
||||
} else {
|
||||
i.SetValue(o.Value)
|
||||
|
@ -2,7 +2,7 @@ package decode
|
||||
|
||||
import "github.com/charmbracelet/lipgloss"
|
||||
|
||||
// Align maps strings to `lipgloss.Position`s
|
||||
// Align maps strings to `lipgloss.Position`s.
|
||||
var Align = map[string]lipgloss.Position{
|
||||
"center": lipgloss.Center,
|
||||
"left": lipgloss.Left,
|
||||
|
@ -2,6 +2,7 @@ package stdin
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
func Read() (string, error) {
|
||||
stat, err := os.Stdin.Stat()
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", errors.New("failed to get stdin stat")
|
||||
}
|
||||
|
||||
if stat.Mode()&os.ModeNamedPipe == 0 && stat.Size() == 0 {
|
||||
|
@ -2,7 +2,7 @@ package style
|
||||
|
||||
import "github.com/charmbracelet/lipgloss"
|
||||
|
||||
// border maps strings to `lipgloss.Border`s
|
||||
// border maps strings to `lipgloss.Border`s.
|
||||
var border map[string]lipgloss.Border = map[string]lipgloss.Border{
|
||||
"double": lipgloss.DoubleBorder(),
|
||||
"hidden": lipgloss.HiddenBorder(),
|
||||
|
@ -5,20 +5,26 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const maxTokens = 4
|
||||
|
||||
// parsePadding parses 1 - 4 integers from a string and returns them in a top,
|
||||
// right, bottom, left order for use in the lipgloss.Padding() method
|
||||
// right, bottom, left order for use in the lipgloss.Padding() method.
|
||||
func parsePadding(s string) (int, int, int, int) {
|
||||
var ints []int
|
||||
var ints [maxTokens]int
|
||||
|
||||
tokens := strings.Split(s, " ")
|
||||
|
||||
if len(tokens) > maxTokens {
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
|
||||
// All tokens must be an integer
|
||||
for _, token := range tokens {
|
||||
for i, token := range tokens {
|
||||
parsed, err := strconv.Atoi(token)
|
||||
if err != nil {
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
ints = append(ints, parsed)
|
||||
ints[i] = parsed
|
||||
}
|
||||
|
||||
if len(tokens) == 1 {
|
||||
@ -29,7 +35,7 @@ func parsePadding(s string) (int, int, int, int) {
|
||||
return ints[0], ints[1], ints[0], ints[1]
|
||||
}
|
||||
|
||||
if len(tokens) == 4 {
|
||||
if len(tokens) == maxTokens {
|
||||
return ints[0], ints[1], ints[2], ints[3]
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user