]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
commands: Validate style argument passed to gen chromastyles
authorJoe Mooring <joe.mooring@veriphor.com>
Fri, 7 Feb 2025 17:36:29 +0000 (09:36 -0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 7 Feb 2025 21:44:22 +0000 (22:44 +0100)
Closes #13357

commands/gen.go
testscripts/commands/gen.txt

index 67aa7a89665d3f55575289cbd1a8faf4024d5ea7..3cb05927d43f11a525380e9b32cf6db56ed31ef6 100644 (file)
@@ -21,6 +21,7 @@ import (
        "os"
        "path"
        "path/filepath"
+       "slices"
        "strings"
 
        "github.com/alecthomas/chroma/v2"
@@ -60,6 +61,10 @@ func newGenCommand() *genCommand {
 See https://xyproto.github.io/splash/docs/all.html for a preview of the available styles`,
 
                        run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
+                               style = strings.ToLower(style)
+                               if !slices.Contains(styles.Names(), style) {
+                                       return fmt.Errorf("invalid style: %s", style)
+                               }
                                builder := styles.Get(style).Builder()
                                if highlightStyle != "" {
                                        builder.Add(chroma.LineHighlight, highlightStyle)
index 092b4e129208361ff759fb9a8667c4cb98c0e6a9..2d57c8ec0ad8c516199fb5d11da84601bc43bb81 100644 (file)
@@ -11,4 +11,6 @@ hugo gen man --dir manpages
 hugo gen chromastyles -h
 stdout 'Generate CSS stylesheet for the Chroma code highlighter'
 hugo gen chromastyles --style monokai
-stdout '/\* LineHighlight \*/ \.chroma \.hl \{ background-color:#3c3d38 \}'
+stdout 'Generated using: hugo gen chromastyles --style monokai'
+! hugo gen chromastyles --style __invalid_style__
+stderr 'invalid style: __invalid_style__'