• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

charmbracelet / glow / 14249847881

03 Apr 2025 06:10PM UTC coverage: 3.722% (-0.007%) from 3.729%
14249847881

Pull #735

github

andreynering
fix(lint): fix all linting issues
Pull Request #735: chore: do some basic repo maintenance (editorconfig, linting, etc)

0 of 86 new or added lines in 14 files covered. (0.0%)

1 existing line in 1 file now uncovered.

77 of 2069 relevant lines covered (3.72%)

0.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.91
/config_cmd.go
1
package main
2

3
import (
4
        "errors"
5
        "fmt"
6
        "io/fs"
7
        "os"
8
        "path"
9
        "path/filepath"
10

11
        "github.com/charmbracelet/x/editor"
12
        "github.com/spf13/cobra"
13
        "github.com/spf13/viper"
14
)
15

16
const defaultConfig = `# style name or JSON path (default "auto")
17
style: "auto"
18
# mouse support (TUI-mode only)
19
mouse: false
20
# use pager to display markdown
21
pager: false
22
# word-wrap at width
23
width: 80
24
# show all files, including hidden and ignored.
25
all: false
26
`
27

28
var configCmd = &cobra.Command{
29
        Use:     "config",
30
        Hidden:  false,
31
        Short:   "Edit the glow config file",
32
        Long:    paragraph(fmt.Sprintf("\n%s the glow config file. We’ll use EDITOR to determine which editor to use. If the config file doesn't exist, it will be created.", keyword("Edit"))),
33
        Example: paragraph("glow config\nglow config --config path/to/config.yml"),
34
        Args:    cobra.NoArgs,
35
        RunE: func(*cobra.Command, []string) error {
×
36
                if err := ensureConfigFile(); err != nil {
×
37
                        return err
×
38
                }
×
39

40
                c, err := editor.Cmd("Glow", configFile)
×
41
                if err != nil {
×
NEW
42
                        return fmt.Errorf("unable to set config file: %w", err)
×
43
                }
×
44
                c.Stdin = os.Stdin
×
45
                c.Stdout = os.Stdout
×
46
                c.Stderr = os.Stderr
×
47
                if err := c.Run(); err != nil {
×
NEW
48
                        return fmt.Errorf("unable to run command: %w", err)
×
49
                }
×
50

51
                fmt.Println("Wrote config file to:", configFile)
×
52
                return nil
×
53
        },
54
}
55

56
func ensureConfigFile() error {
1✔
57
        if configFile == "" {
1✔
58
                configFile = viper.GetViper().ConfigFileUsed()
×
NEW
59
                if err := os.MkdirAll(filepath.Dir(configFile), 0o755); err != nil { //nolint:gosec
×
60
                        return fmt.Errorf("could not write configuration file: %w", err)
×
61
                }
×
62
        }
63

64
        if ext := path.Ext(configFile); ext != ".yaml" && ext != ".yml" {
1✔
65
                return fmt.Errorf("'%s' is not a supported configuration type: use '%s' or '%s'", ext, ".yaml", ".yml")
×
66
        }
×
67

68
        if _, err := os.Stat(configFile); errors.Is(err, fs.ErrNotExist) {
2✔
69
                // File doesn't exist yet, create all necessary directories and
1✔
70
                // write the default config file
1✔
71
                if err := os.MkdirAll(filepath.Dir(configFile), 0o700); err != nil {
1✔
NEW
72
                        return fmt.Errorf("unable create directory: %w", err)
×
73
                }
×
74

75
                f, err := os.Create(configFile)
1✔
76
                if err != nil {
1✔
NEW
77
                        return fmt.Errorf("unable to create config file: %w", err)
×
78
                }
×
79
                defer func() { _ = f.Close() }()
2✔
80

81
                if _, err := f.WriteString(defaultConfig); err != nil {
1✔
NEW
82
                        return fmt.Errorf("unable to write config file: %w", err)
×
83
                }
×
84
        } else if err != nil { // some other error occurred
×
NEW
85
                return fmt.Errorf("unable to stat config file: %w", err)
×
86
        }
×
87
        return nil
1✔
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc