Add gen command
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
564f3c9b05
commit
602a558ab1
|
@ -0,0 +1,46 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
"lure.sh/lure/pkg/gen"
|
||||||
|
)
|
||||||
|
|
||||||
|
var genCmd = &cli.Command{
|
||||||
|
Name: "generate",
|
||||||
|
Usage: "Generate a LURE script from a template",
|
||||||
|
Aliases: []string{"gen"},
|
||||||
|
Subcommands: []*cli.Command{
|
||||||
|
genPipCmd,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var genPipCmd = &cli.Command{
|
||||||
|
Name: "pip",
|
||||||
|
Usage: "Generate a LURE script for a pip module",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "name",
|
||||||
|
Aliases: []string{"n"},
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "version",
|
||||||
|
Aliases: []string{"v"},
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "description",
|
||||||
|
Aliases: []string{"d"},
|
||||||
|
Value: "A Python Pip module",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
return gen.Pip(os.Stdout, gen.PipOptions{
|
||||||
|
Name: c.String("name"),
|
||||||
|
Version: c.String("version"),
|
||||||
|
Description: c.String("description"),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
3
main.go
3
main.go
|
@ -62,8 +62,9 @@ var app = &cli.App{
|
||||||
removerepoCmd,
|
removerepoCmd,
|
||||||
refreshCmd,
|
refreshCmd,
|
||||||
fixCmd,
|
fixCmd,
|
||||||
versionCmd,
|
genCmd,
|
||||||
helperCmd,
|
helperCmd,
|
||||||
|
versionCmd,
|
||||||
},
|
},
|
||||||
Before: func(c *cli.Context) error {
|
Before: func(c *cli.Context) error {
|
||||||
ctx := c.Context
|
ctx := c.Context
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package gen
|
||||||
|
|
||||||
|
import "text/template"
|
||||||
|
|
||||||
|
var funcs = template.FuncMap{
|
||||||
|
"firstchar": func(s string) string {
|
||||||
|
return s[:1]
|
||||||
|
},
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package gen
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "embed"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"path"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed tmpls/pip.tmpl.sh
|
||||||
|
var pipTmpl string
|
||||||
|
|
||||||
|
type PipOptions struct {
|
||||||
|
Name string
|
||||||
|
Version string
|
||||||
|
Description string
|
||||||
|
}
|
||||||
|
|
||||||
|
func Pip(w io.Writer, opts PipOptions) error {
|
||||||
|
tmpl, err := template.New("pip").
|
||||||
|
Funcs(funcs).
|
||||||
|
Parse(pipTmpl)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
params := map[string]any{
|
||||||
|
"name": opts.Name,
|
||||||
|
"version": opts.Version,
|
||||||
|
"description": opts.Description,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf(
|
||||||
|
"https://files.pythonhosted.org/packages/source/%s/%s/%s-%s.tar.gz",
|
||||||
|
opts.Name[:1],
|
||||||
|
opts.Name,
|
||||||
|
opts.Name,
|
||||||
|
opts.Version,
|
||||||
|
)
|
||||||
|
|
||||||
|
res, err := http.Head(url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := path.Dir(res.Request.URL.Path)
|
||||||
|
checksum := path.Base(dir)
|
||||||
|
dir = path.Dir(dir)
|
||||||
|
checksum = path.Base(dir) + checksum
|
||||||
|
dir = path.Dir(dir)
|
||||||
|
checksum = path.Base(dir) + checksum
|
||||||
|
params["checksum"] = "blake2b-256:" + checksum
|
||||||
|
|
||||||
|
return tmpl.Execute(w, params)
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
name='{{.name}}'
|
||||||
|
version='{{.version}}'
|
||||||
|
release='1'
|
||||||
|
desc='{{.description}}'
|
||||||
|
homepage='https://example.com'
|
||||||
|
maintainer='Example <user@example.com>'
|
||||||
|
architectures=('all')
|
||||||
|
license=('custom:Unknown')
|
||||||
|
provides=('{{.name}}')
|
||||||
|
conflicts=('{{.name}}')
|
||||||
|
|
||||||
|
deps=("python3")
|
||||||
|
deps_arch=("python")
|
||||||
|
deps_alpine=("python3")
|
||||||
|
|
||||||
|
build_deps=("python3" "python3-setuptools")
|
||||||
|
build_deps_arch=("python" "python-setuptools")
|
||||||
|
build_deps_alpine=("python3" "py3-setuptools")
|
||||||
|
|
||||||
|
sources=("https://files.pythonhosted.org/packages/source/{{.name | firstchar}}/{{.name}}/{{.name}}-${version}.tar.gz")
|
||||||
|
checksums=('{{.checksum}}')
|
||||||
|
|
||||||
|
build() {
|
||||||
|
cd "$srcdir/{{.name}}-${version}"
|
||||||
|
python3 setup.py build
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
cd "$srcdir/{{.name}}-${version}"
|
||||||
|
python3 setup.py install --root="${pkgdir}/" --optimize=1 || return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue