build 0.0.0.25

This commit is contained in:
2023-06-30 10:09:01 -04:00
parent 3be0c4d9f6
commit 97466a8f71
15 changed files with 1186 additions and 443 deletions
+6 -7
View File
@@ -7,22 +7,21 @@ import (
"os"
)
func loadConfigFile() *Config {
func LoadConfigFile(c *config.Config) *ConfigYml {
filename := config.GetConfigFileName()
cfg, err := LoadConfig(filename)
filename := c.GetConfigFileYmlName()
cfgfile, err := LoadConfig(filename)
if err != nil {
log.Fatalf("error loading config file: %v", err)
os.Exit(1)
}
return cfg
return cfgfile
}
func Listcategory() {
func Listcategory(c *config.Config) {
cfg := loadConfigFile()
cfg := LoadConfigFile(c)
// list all categories
ListCategories, err := cfg.GetListCategory()
+35 -16
View File
@@ -7,11 +7,7 @@ import (
"gopkg.in/yaml.v2"
)
// The above code defines a configuration struct for software projects with sections for software,
// environment variables, directories, and pipeline configurations.
// @property Sections - A map of SectionConfig objects, where each key is a string representing the
// name of the section.
type Config struct {
type ConfigYml struct {
Sections map[string]SectionConfig `yaml:"category"`
}
@@ -46,14 +42,27 @@ type PipelineConfig struct {
Build string `yaml:"build"`
Test string `yaml:"test"`
Lint string `yaml:"lint"`
// Compile string `yaml:"compile"`
// Package string `yaml:"package"`
}
// function GetPathsFromCategory
func (c *ConfigYml) GetPathsFromCategory(sectionName string) ([]string, error) {
section, ok := c.Sections[sectionName]
if !ok {
return nil, fmt.Errorf("section '%s' not found", sectionName)
}
var paths []string
for _, EnvVar := range section.EnvironmentsVariables {
paths = append(paths, EnvVar)
}
return paths, nil
}
// The function loads a configuration file in YAML format and returns a pointer to a Config struct or
// an error.
func LoadConfig(filename string) (*Config, error) {
var config Config
func LoadConfig(filename string) (*ConfigYml, error) {
var config ConfigYml
source, err := ioutil.ReadFile(filename)
if err != nil {
@@ -72,7 +81,7 @@ func LoadConfig(filename string) (*Config, error) {
}
// function GetListCategory return list category from config file
func (c *Config) GetListCategory() ([]string, error) {
func (c *ConfigYml) GetListCategory() ([]string, error) {
var categories []string
for categoryName := range c.Sections {
categories = append(categories, categoryName)
@@ -84,7 +93,7 @@ func (c *Config) GetListCategory() ([]string, error) {
// This is a method defined on the `Config` struct that returns a list of software names for a given
// section. It takes in a `sectionName` string as a parameter and returns a slice of strings and an
// error.
func (c *Config) GetListSoftware(sectionName string) ([]string, error) {
func (c *ConfigYml) GetListSoftware(sectionName string) ([]string, error) {
section, ok := c.Sections[sectionName]
if !ok {
return nil, fmt.Errorf("section '%s' not found", sectionName)
@@ -100,7 +109,7 @@ func (c *Config) GetListSoftware(sectionName string) ([]string, error) {
// This is a method defined on the `Config` struct that takes in two string parameters `sectionName`
// and `SoftwareName`. It returns a pointer to a `SoftwareConfig` struct and an error.
func (c *Config) GetSoftware(sectionName, SoftwareName string) (*SoftwareConfig, error) {
func (c *ConfigYml) GetSoftware(sectionName, SoftwareName string) (*SoftwareConfig, error) {
section, ok := c.Sections[sectionName]
if !ok {
return nil, fmt.Errorf("section '%s' not found", sectionName)
@@ -115,7 +124,7 @@ func (c *Config) GetSoftware(sectionName, SoftwareName string) (*SoftwareConfig,
}
// get list environment variables
func (c *Config) GetListEnvironmentVariables(sectionName string) ([]string, error) {
func (c *ConfigYml) GetListEnvironmentVariables(sectionName string) ([]string, error) {
section, ok := c.Sections[sectionName]
if !ok {
return nil, fmt.Errorf("section '%s' not found", sectionName)
@@ -134,7 +143,7 @@ func (c *Config) GetListEnvironmentVariables(sectionName string) ([]string, erro
// section in the configuration and then looks for the specified environment variable within that
// section. If the section or variable is not found, an error is returned. If the variable is found,
// its value is returned.
func (c *Config) GetEnvironmentVariables(sectionName, variableName string) (string, error) {
func (c *ConfigYml) GetEnvironmentVariables(sectionName, variableName string) (string, error) {
section, ok := c.Sections[sectionName]
if !ok {
return "", fmt.Errorf("section '%s' not found", sectionName)
@@ -148,12 +157,22 @@ func (c *Config) GetEnvironmentVariables(sectionName, variableName string) (stri
return variable, nil
}
// get all environment variables names and values
func (c *ConfigYml) GetAllEnvironmentVariables(sectionName string) (map[string]string, error) {
section, ok := c.Sections[sectionName]
if !ok {
return nil, fmt.Errorf("section '%s' not found", sectionName)
}
return section.EnvironmentsVariables, nil
}
// This is a method defined on the `Config` struct that takes in two string parameters `sectionName`
// and `directoryName`. It returns a pointer to a `DirectoryConfig` struct and an error. The method
// looks for the specified section in the configuration and then looks for the specified directory
// within that section. If the section or directory is not found, an error is returned. If the
// directory is found, its configuration is returned.
func (c *Config) GetDirectory(sectionName, directoryName string) (*DirectoryConfig, error) {
func (c *ConfigYml) GetDirectory(sectionName, directoryName string) (*DirectoryConfig, error) {
section, ok := c.Sections[sectionName]
if !ok {
return nil, fmt.Errorf("section '%s' not found", sectionName)
@@ -173,7 +192,7 @@ func (c *Config) GetDirectory(sectionName, directoryName string) (*DirectoryConf
// for the specified section in the configuration and then looks for the specified pipeline within that
// section. If the section or pipeline is not found, an error is returned. If the pipeline is found,
// its configuration is returned.
func (c *Config) GetPipeline(sectionName, pipelineName string) (*PipelineConfig, error) {
func (c *ConfigYml) GetPipeline(sectionName, pipelineName string) (*PipelineConfig, error) {
section, ok := c.Sections[sectionName]
if !ok {
return nil, fmt.Errorf("section '%s' not found", sectionName)