commands: Validate style argument passed to gen chromastyles - hugo - [fork] hugo port for 9front
 (HTM) git clone git@git.drkhsh.at/hugo.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit a352e69b02ca7d5ea59ba175889365bbbb70303c
 (DIR) parent 1dd27be81aafc44fc3207be675cbac754710be90
 (HTM) Author: Joe Mooring <joe.mooring@veriphor.com>
       Date:   Fri,  7 Feb 2025 09:36:29 -0800
       
       commands: Validate style argument passed to gen chromastyles
       
       Closes #13357
       
       Diffstat:
         M commands/gen.go                     |       5 +++++
         M testscripts/commands/gen.txt        |       4 +++-
       
       2 files changed, 8 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/commands/gen.go b/commands/gen.go
       @@ -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)
 (DIR) diff --git a/testscripts/commands/gen.txt b/testscripts/commands/gen.txt
       @@ -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__'