2024-08-09 17:16:35 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type enbasCLISchema struct {
|
|
|
|
Flags enbasCLISchemaFlagMap `json:"flags"`
|
|
|
|
Commands map[string]enbasCLISchemaCommand `json:"commands"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func newEnbasCLISchemaFromFile(path string) (enbasCLISchema, error) {
|
|
|
|
file, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return enbasCLISchema{}, fmt.Errorf("unable to open the schema file: %w", err)
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
var schema enbasCLISchema
|
|
|
|
|
|
|
|
if err := json.NewDecoder(file).Decode(&schema); err != nil {
|
|
|
|
return enbasCLISchema{}, fmt.Errorf("unable to decode the JSON data: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return schema, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type enbasCLISchemaFlag struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type enbasCLISchemaFlagMap map[string]enbasCLISchemaFlag
|
|
|
|
|
|
|
|
func (e enbasCLISchemaFlagMap) getType(name string) string {
|
|
|
|
flag, ok := e[name]
|
|
|
|
if !ok {
|
|
|
|
return "UNKNOWN TYPE"
|
|
|
|
}
|
|
|
|
|
|
|
|
return flag.Type
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e enbasCLISchemaFlagMap) getDescription(name string) string {
|
|
|
|
flag, ok := e[name]
|
|
|
|
if !ok {
|
|
|
|
return "UNKNOWN DESCRIPTION"
|
|
|
|
}
|
|
|
|
|
|
|
|
return flag.Description
|
|
|
|
}
|
|
|
|
|
|
|
|
type enbasCLISchemaCommand struct {
|
2024-08-09 17:35:44 +01:00
|
|
|
UsePrinter bool `json:"usePrinter"`
|
|
|
|
UseConfig bool `json:"useConfig"`
|
2024-08-09 17:16:35 +01:00
|
|
|
Flags []enbasCLISchemaFlagReference `json:"flags"`
|
|
|
|
Summary string `json:"summary"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type enbasCLISchemaFlagReference struct {
|
|
|
|
Flag string `json:"flag"`
|
|
|
|
Default string `json:"default"`
|
|
|
|
}
|