diff options
Diffstat (limited to 'pkg/config/config.go')
-rw-r--r-- | pkg/config/config.go | 40 |
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{} |