Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &cli.Command{ Name: "config", Usage: "Views or manages project-specific configuration (stored in config directory)", Flags: append([]cli.Flag{ &cli.BoolFlag{ Name: "list", Usage: "Display all current project configuration settings", }, &cli.BoolFlag{ Name: "edit", Usage: "Open config file in a text editor for manual editing", }, &cli.StringSliceFlag{ Name: "set", Usage: "Set a value into the current projects configuration settings (--set project.name=value)", }, }, common.GlobalFlags...), Action: func(cCtx *cli.Context) error { logger := common.LoggerFromContext(cCtx) cfgPath := filepath.Join("config", common.BaseConfig) if cCtx.Bool("edit") { logger.Info("Opening config file for editing...") return EditConfig(cCtx, cfgPath, Config, "") } items := cCtx.StringSlice("set") if len(items) > 0 { items = append(items, cCtx.Args().Slice()...) rootDoc, err := common.LoadYAML(cfgPath) if err != nil { return fmt.Errorf("read config YAML: %w", err) } root := rootDoc.Content[0] configNode := common.GetChildByKey(root, "config") if configNode == nil { configNode = &yaml.Node{Kind: yaml.MappingNode} root.Content = append(root.Content, &yaml.Node{Kind: yaml.ScalarNode, Value: "config"}, configNode, ) } for _, item := range items { idx := strings.LastIndex(item, "=") if idx < 0 { return fmt.Errorf("invalid --set syntax %q (want key=val)", item) } pathStr := item[:idx] val := item[idx+1:] path := strings.Split(pathStr, ".") configNode, err = common.WriteToPath(configNode, path, val) if err != nil { return fmt.Errorf("setting value %s failed: %w", item, err) } logger.Info("Set %s = %s", pathStr, val) } if err := common.WriteYAML(cfgPath, rootDoc); err != nil { return fmt.Errorf("write config YAML: %w", err) } return nil } projectSettings, err := common.LoadProjectSettings() if err != nil { return fmt.Errorf("failed to load project settings to get telemetry status: %v", err) } config, err := common.LoadBaseConfigYaml() if err != nil { return fmt.Errorf("failed to load config and context config: %w", err) } logger.Info("Displaying current configuration... \n\n") logger.Info("Telemetry enabled: %t \n", projectSettings.TelemetryEnabled) logger.Info("Project: %s\n", config.Config.Project.Name) logger.Info("Version: %s\n\n", config.Config.Project.Version) err = common.ListYaml(cfgPath, logger) if err != nil { return fmt.Errorf("failed to list config %w", err) } return nil }, }
View Source
var DefaultConfigPath = filepath.Join("config")
Path to the config directory
Functions ¶
func EditConfig ¶
editConfig is the main entry point for the edit config functionality
func ValidateConfig ¶
func ValidateConfig(configPath string, editTarget EditTarget) ([]byte, error)
ValidateConfig reads configPath into the appropriate struct based on editTarget, then runs requireNonZero on it, returning the raw bytes or an error.
Types ¶
type ConfigChange ¶
type ConfigChange struct {
Path string
OldValue interface{}
NewValue interface{}
}
ConfigChange represents a change in a configuration field
type EditTarget ¶
type EditTarget int
Iota based enum for types of config
const ( Config EditTarget = iota Context )
Click to show internal directories.
Click to hide internal directories.