Skip to content

Commit

Permalink
feat: export 'parse' function
Browse files Browse the repository at this point in the history
  • Loading branch information
moyiz committed May 27, 2024
1 parent 1ed7a36 commit 2ccde0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ shallow clones automatically. It aims to provide a similar experience to
- [Parameters](#parameters)
- [Examples](#examples)
- [:broom: Clean All](#broom-clean-all)
- [:eyeglasses: Parse](#eyeglasses-parse)
- [:gear: Options](#gear-options)
- [:spider_web: URL Parsing (experimental)](#spider_web-url-parsing-experimental)
- [:spider_web: URL Parsing](#spider_web-url-parsing)
- [Supported URLs](#supported-urls)
- [Examples](#examples)
- [Limitations](#limitations)
Expand Down Expand Up @@ -132,6 +133,10 @@ purpose.
By either using the lua function `require("git-dev").clean_all()` or the command
`GitDevCleanAll`.

### :eyeglasses: Parse
Parses a Git URL.
See [URL Parsing](#spider_web-url-parsing).


## :gear: Options
```lua
Expand Down Expand Up @@ -187,7 +192,7 @@ M.config = {
}
```

## :spider_web: URL Parsing (experimental)
## :spider_web: URL Parsing
It is reasonable to assume that browsing arbitrary Git repositories will
probably begin in a web browser. The main purpose of this feature is to allow
quicker transition from the currently viewed branch / tag / commit / file to
Expand Down
14 changes: 14 additions & 0 deletions lua/git-dev/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,20 @@ M.clean_all = function()
vim.fn.delete(M.config.repositories_dir)
end

---Parses a Git URL.
---@param repo string
---@return GitRepo
M.parse = function(repo, opts)
local config = vim.tbl_deep_extend("force", M.config, opts or {})
local gitcmd = require("git-dev.gitcmd"):init { cmd = config.git.command }
local parser = require("git-dev.parser"):init {
gitcmd = gitcmd,
base_uri_format = config.git.base_uri_format,
extra_domain_to_parser = config.extra_domain_to_parser,
}
return parser:parse(repo)
end

---Module Setup
---@param opts? table Module config table. See |M.config|.
M.setup = function(opts)
Expand Down

0 comments on commit 2ccde0c

Please sign in to comment.