Skip to content

Commit

Permalink
docs: updated docs with supported parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
retr0h committed Jun 23, 2024
1 parent 00f725f commit a3faa1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
41 changes: 14 additions & 27 deletions docs/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,30 @@ sidebar_position: 4

See example client in `examples/go-client/`.

Currently supports the following parsers:

- GitHub
- GitLab

```go
package main

import (
"log/slog"
"os"
"time"

"github.com/lmittmann/tint"

"github.com/retr0h/git-url-parse/pkg"
"github.com/retr0h/git-url-parse/pkg/repository"
)

var logger = slog.New(slog.NewTextHandler(os.Stdout, nil))

type repositoryManager interface {
RegisterParser(url string) error
Parse() (pkg.RepositoryManager, error)
}

func getLogger(debug bool) *slog.Logger {
logLevel := slog.LevelInfo
if debug {
logLevel = slog.LevelDebug
}

logger := slog.New(
tint.NewHandler(os.Stderr, &tint.Options{
Level: logLevel,
TimeFormat: time.Kitchen,
}),
)

return logger
}

func main() {
debug := true
logger := getLogger(debug)
var r repositoryManager = repository.New(logger)

r.RegisterParser("https://github.com/retr0h/foo")
Expand All @@ -56,13 +42,14 @@ func main() {
panic(err)
}

logger.Info(repo.GetProtocol())
logger.Info(repo.GetResourceName())
logger.Info(repo.GetHREF())
logger.Info(repo.GetOwnerName())
logger.Info(repo.GetRepoName())
logger.Info(repo.GetProtocol()) // https
logger.Info(repo.GetProtocols()[0]) // https
logger.Info(repo.GetResourceName()) // github.com
logger.Info(repo.GetHREF()) // https://github.com/retr0h/foo
logger.Info(repo.GetOwnerName()) // retr0h
logger.Info(repo.GetRepoName()) // foo
logger.Info(repo.GetPath())
logger.Info(repo.GetBranchName())
logger.Info(repo.GetProviderName())
logger.Info(repo.GetProviderName()) // github
}
```
1 change: 1 addition & 0 deletions examples/go-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func main() {
}

logger.Info(repo.GetProtocol())
logger.Info(repo.GetProtocols()[0])
logger.Info(repo.GetResourceName())
logger.Info(repo.GetHREF())
logger.Info(repo.GetOwnerName())
Expand Down

0 comments on commit a3faa1f

Please sign in to comment.