From 2ccde0c6fa4d23cb3042c3f99e0856e369824279 Mon Sep 17 00:00:00 2001 From: moyiz <8603313+moyiz@users.noreply.github.com> Date: Mon, 27 May 2024 23:50:47 +0300 Subject: [PATCH] feat: export 'parse' function --- README.md | 9 +++++++-- lua/git-dev/init.lua | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 97f686f..938169d 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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 diff --git a/lua/git-dev/init.lua b/lua/git-dev/init.lua index 550d0a2..f2efd3d 100644 --- a/lua/git-dev/init.lua +++ b/lua/git-dev/init.lua @@ -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)