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

charmbracelet / glow / 5999566226

28 Aug 2023 12:05PM UTC coverage: 6.945% (+0.05%) from 6.899%
5999566226

push

github

web-flow
fix: handle running inside a snap (#527)

* fix: handle running inside a snap

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* test: fixes

* docs: improve error message

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Co-authored-by: bashbunni <bunni@bashbunni.dev>

16 of 16 new or added lines in 3 files covered. (100.0%)

196 of 2822 relevant lines covered (6.95%)

3.0 hits per line

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

0.0
/config_cmd.go
1
package main
2

3
import (
4
        "fmt"
5
        "os"
6
        "path"
7
        "path/filepath"
8

9
        "github.com/charmbracelet/glow/editor"
10
        gap "github.com/muesli/go-app-paths"
11
        "github.com/spf13/cobra"
12
)
13

14
const defaultConfig = `# style name or JSON path (default "auto")
15
style: "auto"
16
# show local files only; no network (TUI-mode only)
17
local: false
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

25
var configCmd = &cobra.Command{
26
        Use:          "config",
27
        Hidden:       false,
28
        Short:        "Edit the glow config file",
29
        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"))),
30
        Example:      paragraph("glow config\nglow config --config path/to/config.yml"),
31
        Args:         cobra.NoArgs,
32
        SilenceUsage: true,
33
        RunE: func(_ *cobra.Command, _ []string) error {
×
34
                if configFile == "" {
×
35
                        scope := gap.NewScope(gap.User, "glow")
×
36

×
37
                        var err error
×
38
                        configFile, err = scope.ConfigPath("glow.yml")
×
39
                        if err != nil {
×
40
                                return err
×
41
                        }
×
42
                }
43

44
                if ext := path.Ext(configFile); ext != ".yaml" && ext != ".yml" {
×
45
                        return fmt.Errorf("'%s' is not a supported config type: use '%s' or '%s'", ext, ".yaml", ".yml")
×
46
                }
×
47

48
                if _, err := os.Stat(configFile); os.IsNotExist(err) {
×
49
                        // File doesn't exist yet, create all necessary directories and
×
50
                        // write the default config file
×
51
                        if err := os.MkdirAll(filepath.Dir(configFile), 0o700); err != nil {
×
52
                                return err
×
53
                        }
×
54

55
                        f, err := os.Create(configFile)
×
56
                        if err != nil {
×
57
                                return err
×
58
                        }
×
59
                        defer func() { _ = f.Close() }()
×
60

61
                        if _, err := f.WriteString(defaultConfig); err != nil {
×
62
                                return err
×
63
                        }
×
64
                } else if err != nil { // some other error occurred
×
65
                        return err
×
66
                }
×
67

68
                c, err := editor.Cmd(configFile)
×
69
                if err != nil {
×
70
                        return fmt.Errorf("could not edit %s: %w", configFile, err)
×
71
                }
×
72
                c.Stdin = os.Stdin
×
73
                c.Stdout = os.Stdout
×
74
                c.Stderr = os.Stderr
×
75
                if err := c.Run(); err != nil {
×
76
                        return err
×
77
                }
×
78

79
                fmt.Println("Wrote config file to:", configFile)
×
80
                return nil
×
81
        },
82
}
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