feat: added info function
parent
3d39132646
commit
7efa42f1e5
|
@ -0,0 +1,28 @@
|
|||
# =====CONFIG=====
|
||||
V_PATH ?= v
|
||||
V := $(V_PATH) -showcc
|
||||
|
||||
all: aur
|
||||
|
||||
|
||||
# =====COMPILATION=====
|
||||
.PHONY: aur
|
||||
aur:
|
||||
$(V) -g -shared .
|
||||
|
||||
|
||||
# =====DOCS=====
|
||||
.PHONY: api-docs
|
||||
api-docs:
|
||||
rm -rf '_docs'
|
||||
v doc -f html -m -readme .
|
||||
|
||||
|
||||
# =====OTHER=====
|
||||
.PHONY: lint
|
||||
lint:
|
||||
$(V) fmt -verify .
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
$(V) fmt -w .
|
22
aur.v
22
aur.v
|
@ -28,3 +28,25 @@ pub:
|
|||
license []string [json: License]
|
||||
keywords []string [json: Keywords]
|
||||
}
|
||||
|
||||
pub enum SearchType {
|
||||
name
|
||||
name_desc
|
||||
maintainer
|
||||
depends
|
||||
make_depends
|
||||
opt_depends
|
||||
check_depends
|
||||
}
|
||||
|
||||
pub fn (st SearchType) str() string {
|
||||
return match st {
|
||||
.name { 'name' }
|
||||
.name_desc { 'name-desc' }
|
||||
.maintainer { 'maintainer' }
|
||||
.depends { 'depends' }
|
||||
.make_depends { 'makedepends' }
|
||||
.opt_depends { 'optdepends' }
|
||||
.check_depends { 'checkdepends' }
|
||||
}
|
||||
}
|
||||
|
|
36
client.v
36
client.v
|
@ -29,16 +29,14 @@ struct SuccessResponse {
|
|||
results []Package
|
||||
}
|
||||
|
||||
fn (c Client) request(params map[string]string) ?[]Package {
|
||||
mut params_escaped := map[string]string{}
|
||||
fn (c Client) request(params map[string][]string) ?[]Package {
|
||||
mut param_strings := []string{}
|
||||
|
||||
for k, v in params {
|
||||
params_escaped[k] = urllib.query_escape(v)
|
||||
param_strings << v.map(urllib.query_escape(it)).map('$k=$it')
|
||||
}
|
||||
|
||||
params_str := params_escaped.keys().map('$it=${params[it]}').join('&')
|
||||
|
||||
url := '$c.url?$params_str'
|
||||
url := '$c.url?${param_strings.join('&')}'
|
||||
|
||||
res := http.get(url)?
|
||||
|
||||
|
@ -51,3 +49,29 @@ fn (c Client) request(params map[string]string) ?[]Package {
|
|||
|
||||
return data.results
|
||||
}
|
||||
|
||||
pub fn (c Client) search_by(arg string, st SearchType) ?[]Package {
|
||||
params := {
|
||||
'v': ['5']
|
||||
'type': ['search']
|
||||
'by': ['$st']
|
||||
'arg': [arg]
|
||||
}
|
||||
|
||||
return c.request(params)
|
||||
}
|
||||
|
||||
// search performs a search by name_desc.
|
||||
pub fn (c Client) search(arg string) ?[]Package {
|
||||
return c.search_by(arg, .name_desc)
|
||||
}
|
||||
|
||||
pub fn (c Client) info(pkgs []string) ?[]Package {
|
||||
params := {
|
||||
'v': ['5']
|
||||
'type': ['info']
|
||||
'arg[]': pkgs
|
||||
}
|
||||
|
||||
return c.request(params)
|
||||
}
|
||||
|
|
39
search.v
39
search.v
|
@ -1,39 +0,0 @@
|
|||
module aur
|
||||
|
||||
pub enum SearchType {
|
||||
name
|
||||
name_desc
|
||||
maintainer
|
||||
depends
|
||||
make_depends
|
||||
opt_depends
|
||||
check_depends
|
||||
}
|
||||
|
||||
pub fn (st SearchType) str() string {
|
||||
return match st {
|
||||
.name { 'name' }
|
||||
.name_desc { 'name-desc' }
|
||||
.maintainer { 'maintainer' }
|
||||
.depends { 'depends' }
|
||||
.make_depends { 'makedepends' }
|
||||
.opt_depends { 'optdepends' }
|
||||
.check_depends { 'checkdepends' }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (c Client) search_by(arg string, st SearchType) ?[]Package {
|
||||
params := {
|
||||
'v': '5'
|
||||
'type': 'search'
|
||||
'by': '$st'
|
||||
'arg': arg
|
||||
}
|
||||
|
||||
return c.request(params)
|
||||
}
|
||||
|
||||
// search performs a search by name_desc.
|
||||
pub fn (c Client) search(arg string) ?[]Package {
|
||||
return c.search_by(arg, .name_desc)
|
||||
}
|
Loading…
Reference in New Issue