feat: introduce abra config file and load abra dir from it #419
Reference in New Issue
Block a user
No description provided.
Delete Branch "p4u1/abra:introduce-abra-config"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is the first step to introduce a configuration file for abra. The config file must be named
abra.yamlor àbra.yml`. abra look for the config file in the current directory and when not found traverses the directory tree up until it is found or the home/root directory is reached.For now there is only one setting that is made configurable:
abraDir. The new logic for setting the abra dir is the following:$ABRA_DIRenv$HOME/.abraas fallbackSee coop-cloud/organising#303.
Todo:
Nice, love to see it! Ping me for a review when it's GTG 🎉
The only thing I'd mention at this point is that people do
.yaml/.ymlso you might want to do some sort of grep-enabled find for the file ending.... otherwise, we can 100% count on a bug report in the future 😆5eb285bf82to7789978582config: automatic base dir when abra.yaml was foundto feat: introduce abra config file and load abra dir from it7789978582tob8276f149eb8276f149eto5ecde18a3d@decentral1se Thanks for the feedback and linking to the issue! After reading the issue again I changed the logic to take the abra dir from a concrete value (
abraDir) in the config file instead of setting it to the directory of the config file.I also added some tests and added
abra.ymlas another valid config file name.Great stuff @p4u1! Minor comments, feel free to merge 💝
@ -0,0 +11,4 @@// LoadAbraConfig returns the abra configuration. It tries to find a abra// configuration file (see findAbraConfig for lookup logic). When no// configuration was was found it returns the default config.%s/was was/was/@ -0,0 +16,4 @@wd, _ := os.Getwd()configFile := findAbraConfig(wd)if configFile == "" {logrus.Info("no config file found")Perhaps
Warnfis best? No error and coloured output?Changed it to debug output for now, but can always change this later
@ -0,0 +22,4 @@data, err := os.ReadFile(configFile)if err != nil {// Do nothing, when an error occurslogrus.Infof("error reading config file: %s", err)https://git.coopcloud.tech/coop-cloud/abra/pulls/419/files#issuecomment-20723
@ -0,0 +30,4 @@err = yaml.Unmarshal(data, &config)if err != nil {// Do nothing, when an error occurslogrus.Infof("error loading config file: %s", err)https://git.coopcloud.tech/coop-cloud/abra/pulls/419/files#issuecomment-20723
@ -0,0 +62,4 @@// Abra defines the configuration file for abra.type Abra struct {AbraDir string `yaml:"abraDir"`Abra.Dir? No strong feelings tho.I left it for now, but am open to changing it later :)
5ecde18a3dtod26645fbdfd26645fbdfto97ae6ac267@decentral1se can you have a look at the test failure? It works for me locally
@ -0,0 +63,4 @@})t.Run("from config file", func(t *testing.T) {wd, err := os.Getwd()Maybe this is borking it? Not sure otherwise 🤔
wasn't borking it, but removed it anyways
@decentral1se there error was because the tests are run with an $ABRA_DIR set... this always overrides the config file. I unset it at the begging of the test now