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