aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/config.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2025-02-06 23:47:51 +0100
committerGabriel A. Giovanini <mail@gabrielgio.me>2025-02-06 23:47:51 +0100
commit30d722da053fb4007b897cb201418b4fed544ace (patch)
tree264bb54efdf7d5d42736436772c4f21951ac19d8 /pkg/config/config.go
parente8265117372cf262ce7cb4f6ce3b61f19373aee6 (diff)
downloadcerrado-56d346178e364c186e7b6029c15810502ebccd9c.tar.gz
cerrado-56d346178e364c186e7b6029c15810502ebccd9c.tar.bz2
cerrado-56d346178e364c186e7b6029c15810502ebccd9c.zip
feat: Add option for remove ".git" suffixv0.0.20
Diffstat (limited to 'pkg/config/config.go')
-rw-r--r--pkg/config/config.go40
1 files changed, 30 insertions, 10 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 60a3444..9dbf449 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -9,6 +9,7 @@ import (
"path"
"path/filepath"
"strconv"
+ "strings"
"git.gabrielgio.me/cerrado/pkg/u"
"git.sr.ht/~emersion/go-scfg"
@@ -41,14 +42,15 @@ type (
// configuration represents file configuration.
// fields needs to be exported to cmp to work
configuration struct {
- Scans []*scan
- RootReadme string
- ListenAddr string
- Passphrase string
- SyntaxHighlight string
AESKey string
+ ListenAddr string
OrderBy string
+ Passphrase string
+ RemoveSuffix bool
Repositories []*GitRepositoryConfiguration
+ RootReadme string
+ Scans []*scan
+ SyntaxHighlight string
}
// This is a per repository configuration.
@@ -65,13 +67,14 @@ type (
// This holds all the function necessary to ask for configuration
// information.
ConfigurationRepository struct {
- rootReadme string
- listenAddr string
- passphrase []byte
aesKey []byte
- syntaxHighlight string
+ listenAddr string
orderBy OrderBy
+ passphrase []byte
+ removeSuffix bool
repositories []*GitRepositoryConfiguration
+ rootReadme string
+ syntaxHighlight string
}
)
@@ -93,6 +96,7 @@ func LoadConfigurationRepository(configPath string) (*ConfigurationRepository, e
repositories: config.Repositories,
rootReadme: config.RootReadme,
syntaxHighlight: config.SyntaxHighlight,
+ removeSuffix: config.RemoveSuffix,
orderBy: parseOrderBy(config.OrderBy),
}
@@ -172,8 +176,14 @@ func (c *ConfigurationRepository) expandOnScanPath(scanPath string, public bool)
fullPath := path.Join(scanPath, e.Name())
if !c.repoExits(fullPath) {
+
+ name := e.Name()
+ if c.removeSuffix {
+ name = strings.TrimSuffix(name, ".git")
+ }
+
c.repositories = append(c.repositories, &GitRepositoryConfiguration{
- Name: e.Name(),
+ Name: name,
Path: fullPath,
Public: public,
})
@@ -234,6 +244,11 @@ func parse(r io.Reader) (*configuration, error) {
return nil, err
}
+ err = setRemoveSuffix(block, &config.RemoveSuffix)
+ if err != nil {
+ return nil, err
+ }
+
err = setRepositories(block, &config.Repositories)
if err != nil {
return nil, err
@@ -349,6 +364,11 @@ func setListenAddr(block scfg.Block, listenAddr *string) error {
return setString(scanDir, listenAddr)
}
+func setRemoveSuffix(block scfg.Block, remove *bool) error {
+ scanDir := block.Get("remove-suffix")
+ return setBool(scanDir, remove)
+}
+
func setScan(block scfg.Block, scans *[]*scan) error {
for _, scanDir := range block.GetAll("scan") {
s := &scan{}