11package cmd
22
33import (
4+ "encoding/json"
45 "fmt"
56 "os"
67 "strconv"
@@ -20,9 +21,22 @@ const (
2021 configKeyPageSize
2122)
2223
24+ // configCategory groups related configuration keys.
25+ type configCategory string
26+
27+ const (
28+ categoryTypography configCategory = "Typography"
29+ categoryCode configCategory = "Code Styling"
30+ categoryPage configCategory = "Page Layout"
31+ categoryMetadata configCategory = "PDF Metadata"
32+ categoryMermaid configCategory = "Mermaid Settings"
33+ )
34+
2335// configKeyDef defines metadata for a configuration key including validation rules.
2436type configKeyDef struct {
2537 name string
38+ category configCategory
39+ description string
2640 keyType configKeyType
2741 defaultValue interface {}
2842 minValue float64
@@ -37,6 +51,8 @@ var configKeys = []configKeyDef{
3751 // Typography & Fonts
3852 {
3953 name : "font-family" ,
54+ category : categoryTypography ,
55+ description : "Font family for body text (Arial, Times, Helvetica, Courier)" ,
4056 keyType : configKeyString ,
4157 defaultValue : "Arial" ,
4258 getter : func (c * config.UserConfig ) interface {} { return c .FontFamily },
@@ -45,6 +61,8 @@ var configKeys = []configKeyDef{
4561 },
4662 {
4763 name : "font-size" ,
64+ category : categoryTypography ,
65+ description : "Font size in points (range: 1-72)" ,
4866 keyType : configKeyFloat64 ,
4967 defaultValue : 12.0 ,
5068 minValue : core .FontSizeMin ,
@@ -55,6 +73,8 @@ var configKeys = []configKeyDef{
5573 },
5674 {
5775 name : "heading-scale" ,
76+ category : categoryTypography ,
77+ description : "Heading size multiplier (range: 0.1-10.0)" ,
5878 keyType : configKeyFloat64 ,
5979 defaultValue : 1.5 ,
6080 minValue : core .HeadingScaleMin ,
@@ -65,6 +85,8 @@ var configKeys = []configKeyDef{
6585 },
6686 {
6787 name : "line-spacing" ,
88+ category : categoryTypography ,
89+ description : "Line spacing multiplier (range: 0.1-5.0)" ,
6890 keyType : configKeyFloat64 ,
6991 defaultValue : 1.2 ,
7092 minValue : core .LineSpacingMin ,
@@ -76,6 +98,8 @@ var configKeys = []configKeyDef{
7698 // Code styling
7799 {
78100 name : "code-font" ,
101+ category : categoryCode ,
102+ description : "Font family for code blocks (typically monospace)" ,
79103 keyType : configKeyString ,
80104 defaultValue : "Courier" ,
81105 getter : func (c * config.UserConfig ) interface {} { return c .CodeFont },
@@ -84,6 +108,8 @@ var configKeys = []configKeyDef{
84108 },
85109 {
86110 name : "code-size" ,
111+ category : categoryCode ,
112+ description : "Font size for code blocks in points (range: 6-48)" ,
87113 keyType : configKeyFloat64 ,
88114 defaultValue : 10.0 ,
89115 minValue : core .CodeSizeMin ,
@@ -95,6 +121,8 @@ var configKeys = []configKeyDef{
95121 // Page layout
96122 {
97123 name : "page-size" ,
124+ category : categoryPage ,
125+ description : "Page size (A3, A4, A5, Letter, Legal, Tabloid)" ,
98126 keyType : configKeyPageSize ,
99127 defaultValue : "A4" ,
100128 getter : func (c * config.UserConfig ) interface {} { return c .PageSize },
@@ -103,6 +131,8 @@ var configKeys = []configKeyDef{
103131 },
104132 {
105133 name : "margin-top" ,
134+ category : categoryPage ,
135+ description : "Top margin in mm (range: 0-100)" ,
106136 keyType : configKeyFloat64 ,
107137 defaultValue : 20.0 ,
108138 minValue : core .MarginMin ,
@@ -113,6 +143,8 @@ var configKeys = []configKeyDef{
113143 },
114144 {
115145 name : "margin-bottom" ,
146+ category : categoryPage ,
147+ description : "Bottom margin in mm (range: 0-100)" ,
116148 keyType : configKeyFloat64 ,
117149 defaultValue : 20.0 ,
118150 minValue : core .MarginMin ,
@@ -123,6 +155,8 @@ var configKeys = []configKeyDef{
123155 },
124156 {
125157 name : "margin-left" ,
158+ category : categoryPage ,
159+ description : "Left margin in mm (range: 0-100)" ,
126160 keyType : configKeyFloat64 ,
127161 defaultValue : 15.0 ,
128162 minValue : core .MarginMin ,
@@ -133,6 +167,8 @@ var configKeys = []configKeyDef{
133167 },
134168 {
135169 name : "margin-right" ,
170+ category : categoryPage ,
171+ description : "Right margin in mm (range: 0-100)" ,
136172 keyType : configKeyFloat64 ,
137173 defaultValue : 15.0 ,
138174 minValue : core .MarginMin ,
@@ -144,6 +180,8 @@ var configKeys = []configKeyDef{
144180 // PDF metadata
145181 {
146182 name : "title" ,
183+ category : categoryMetadata ,
184+ description : "PDF document title (embedded in PDF metadata)" ,
147185 keyType : configKeyString ,
148186 defaultValue : "" ,
149187 getter : func (c * config.UserConfig ) interface {} { return c .Title },
@@ -152,6 +190,8 @@ var configKeys = []configKeyDef{
152190 },
153191 {
154192 name : "author" ,
193+ category : categoryMetadata ,
194+ description : "PDF document author (embedded in PDF metadata)" ,
155195 keyType : configKeyString ,
156196 defaultValue : "" ,
157197 getter : func (c * config.UserConfig ) interface {} { return c .Author },
@@ -160,6 +200,8 @@ var configKeys = []configKeyDef{
160200 },
161201 {
162202 name : "subject" ,
203+ category : categoryMetadata ,
204+ description : "PDF document subject (embedded in PDF metadata)" ,
163205 keyType : configKeyString ,
164206 defaultValue : "" ,
165207 getter : func (c * config.UserConfig ) interface {} { return c .Subject },
@@ -169,6 +211,8 @@ var configKeys = []configKeyDef{
169211 // Mermaid settings
170212 {
171213 name : "mermaid-scale" ,
214+ category : categoryMermaid ,
215+ description : "Mermaid diagram scale factor (range: 0.1-10.0)" ,
172216 keyType : configKeyFloat64 ,
173217 defaultValue : 2.2 ,
174218 minValue : core .MermaidScaleMin ,
@@ -179,6 +223,8 @@ var configKeys = []configKeyDef{
179223 },
180224 {
181225 name : "mermaid-max-width" ,
226+ category : categoryMermaid ,
227+ description : "Max diagram width in mm, 0=page width (range: 0-1000)" ,
182228 keyType : configKeyFloat64 ,
183229 defaultValue : 0.0 ,
184230 minValue : core .MermaidDimensionMin ,
@@ -189,6 +235,8 @@ var configKeys = []configKeyDef{
189235 },
190236 {
191237 name : "mermaid-max-height" ,
238+ category : categoryMermaid ,
239+ description : "Max diagram height in mm (range: 0-1000)" ,
192240 keyType : configKeyFloat64 ,
193241 defaultValue : 150.0 ,
194242 minValue : core .MermaidDimensionMin ,
@@ -218,6 +266,24 @@ func validKeysString() string {
218266 return strings .Join (keys , ", " )
219267}
220268
269+ // getKeysByCategory returns all keys grouped by category in display order.
270+ func getKeysByCategory () map [configCategory ][]configKeyDef {
271+ result := make (map [configCategory ][]configKeyDef )
272+ for _ , k := range configKeys {
273+ result [k .category ] = append (result [k .category ], k )
274+ }
275+ return result
276+ }
277+
278+ // categoryOrder defines the display order for categories.
279+ var categoryOrder = []configCategory {
280+ categoryTypography ,
281+ categoryCode ,
282+ categoryPage ,
283+ categoryMetadata ,
284+ categoryMermaid ,
285+ }
286+
221287var configCmd = & cobra.Command {
222288 Use : "config" ,
223289 Short : "Manage configuration settings" ,
@@ -338,6 +404,115 @@ var configResetCmd = &cobra.Command{
338404 },
339405}
340406
407+ // configKeysJSONMode tracks whether to output JSON format
408+ var configKeysJSONMode bool
409+
410+ var configKeysCmd = & cobra.Command {
411+ Use : "keys" ,
412+ Short : "List all available configuration keys" ,
413+ Long : "Display all available configuration keys with descriptions and default values" ,
414+ RunE : func (cmd * cobra.Command , args []string ) error {
415+ if configKeysJSONMode {
416+ return printConfigKeysJSON ()
417+ }
418+ return printConfigKeysText ()
419+ },
420+ }
421+
422+ // printConfigKeysText outputs configuration keys in human-readable format.
423+ func printConfigKeysText () error {
424+ output := uiOutput
425+
426+ output .Info ("Available configuration keys:" )
427+ output .Println ()
428+
429+ keysByCategory := getKeysByCategory ()
430+
431+ for _ , cat := range categoryOrder {
432+ keys , ok := keysByCategory [cat ]
433+ if ! ok {
434+ continue
435+ }
436+
437+ // Print category header
438+ output .Println (output .Bold (string (cat ) + ":" ))
439+
440+ for _ , k := range keys {
441+ // Format: key-name description (default: value)
442+ defaultStr := formatDefaultValue (k .defaultValue )
443+ fmt .Printf (" %s\n " , output .Highlight (k .name ))
444+ fmt .Printf (" %s (default: %s)\n " , k .description , defaultStr )
445+ }
446+ output .Println ()
447+ }
448+
449+ return nil
450+ }
451+
452+ // configKeyJSON represents a config key in JSON format.
453+ type configKeyJSON struct {
454+ Name string `json:"name"`
455+ Category string `json:"category"`
456+ Description string `json:"description"`
457+ Type string `json:"type"`
458+ DefaultValue interface {} `json:"default"`
459+ MinValue * float64 `json:"min,omitempty"`
460+ MaxValue * float64 `json:"max,omitempty"`
461+ }
462+
463+ // printConfigKeysJSON outputs configuration keys in JSON format.
464+ func printConfigKeysJSON () error {
465+ var keys []configKeyJSON
466+
467+ for i := range configKeys {
468+ k := & configKeys [i ]
469+ keyJSON := configKeyJSON {
470+ Name : k .name ,
471+ Category : string (k .category ),
472+ Description : k .description ,
473+ DefaultValue : k .defaultValue ,
474+ }
475+
476+ switch k .keyType {
477+ case configKeyString :
478+ keyJSON .Type = "string"
479+ case configKeyFloat64 :
480+ keyJSON .Type = "number"
481+ // Copy values to avoid pointer issues
482+ minVal := k .minValue
483+ maxVal := k .maxValue
484+ keyJSON .MinValue = & minVal
485+ keyJSON .MaxValue = & maxVal
486+ case configKeyPageSize :
487+ keyJSON .Type = "enum"
488+ }
489+
490+ keys = append (keys , keyJSON )
491+ }
492+
493+ encoder := json .NewEncoder (os .Stdout )
494+ encoder .SetIndent ("" , " " )
495+ return encoder .Encode (keys )
496+ }
497+
498+ // formatDefaultValue returns a string representation of a default value.
499+ func formatDefaultValue (v interface {}) string {
500+ switch val := v .(type ) {
501+ case string :
502+ if val == "" {
503+ return "(none)"
504+ }
505+ return fmt .Sprintf ("%q" , val )
506+ case float64 :
507+ if val == float64 (int (val )) {
508+ return fmt .Sprintf ("%.0f" , val )
509+ }
510+ return fmt .Sprintf ("%.1f" , val )
511+ default :
512+ return fmt .Sprintf ("%v" , v )
513+ }
514+ }
515+
341516// printConfigValueFromKey prints a config value using the registry.
342517func printConfigValueFromKey (userConfig * config.UserConfig , keyName string ) {
343518 keyDef := findConfigKey (keyName )
@@ -421,4 +596,8 @@ func init() {
421596 configCmd .AddCommand (configListCmd )
422597 configCmd .AddCommand (configSetCmd )
423598 configCmd .AddCommand (configResetCmd )
599+ configCmd .AddCommand (configKeysCmd )
600+
601+ // Add --json flag to keys command
602+ configKeysCmd .Flags ().BoolVar (& configKeysJSONMode , "json" , false , "Output in JSON format" )
424603}
0 commit comments