112 lines
2 KiB
Go
112 lines
2 KiB
Go
|
package state
|
||
|
|
||
|
import (
|
||
|
"code.vulpine.solutions/sam/vlp/internal/build"
|
||
|
"code.vulpine.solutions/sam/vlp/internal/packages"
|
||
|
lua "github.com/yuin/gopher-lua"
|
||
|
)
|
||
|
|
||
|
func (s *State) depends(ls *lua.LState) int {
|
||
|
t := ls.GetTop()
|
||
|
if t == 0 {
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
for i := 1; i <= t; i++ {
|
||
|
table, ok := ls.Get(i).(*lua.LTable)
|
||
|
if !ok {
|
||
|
ls.RaiseError("Argument %v was not a table", i)
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
var (
|
||
|
name string
|
||
|
version = "*"
|
||
|
)
|
||
|
|
||
|
switch table.Len() {
|
||
|
default:
|
||
|
fallthrough
|
||
|
case 2:
|
||
|
version = table.RawGetInt(2).String()
|
||
|
fallthrough
|
||
|
case 1:
|
||
|
name = table.RawGetInt(1).String()
|
||
|
case 0:
|
||
|
ls.RaiseError("Table %v is empty", i)
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
s.Builder.Dependencies = append(s.Builder.Dependencies, packages.Dependency{Name: name, Version: version})
|
||
|
}
|
||
|
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
func (s *State) git(ls *lua.LState) int {
|
||
|
t := ls.GetTop()
|
||
|
if t == 0 {
|
||
|
ls.RaiseError("`git` needs a repository URL")
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
var repo, ref string
|
||
|
|
||
|
lrepo, ok := ls.Get(1).(lua.LString)
|
||
|
if !ok {
|
||
|
ls.RaiseError("Argument 1 is not a string")
|
||
|
return 0
|
||
|
}
|
||
|
repo = lrepo.String()
|
||
|
|
||
|
lref, ok := ls.Get(2).(lua.LString)
|
||
|
if ok {
|
||
|
ref = lref.String()
|
||
|
}
|
||
|
|
||
|
s.Builder.SourceFetcher = build.GitFetcher{Repository: repo, Ref: ref}
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
func (s *State) cmd(ls *lua.LState) int {
|
||
|
t := ls.GetTop()
|
||
|
if t == 0 {
|
||
|
ls.RaiseError("`cmd` needs a command to run")
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
lcmd, ok := ls.Get(1).(lua.LString)
|
||
|
if !ok {
|
||
|
ls.RaiseError("Argument 1 is not a string")
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
var args []string
|
||
|
for i := 2; i <= t; i++ {
|
||
|
larg := ls.Get(i)
|
||
|
if larg == lua.LNil {
|
||
|
break
|
||
|
}
|
||
|
args = append(args, larg.String())
|
||
|
}
|
||
|
|
||
|
s.Builder.Commands = append(s.Builder.Commands, build.BuildCommand{Command: lcmd.String(), Args: args})
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
func (s *State) bin(ls *lua.LState) int {
|
||
|
if ls.GetTop() != 1 {
|
||
|
ls.RaiseError("`bin` needs a single binary to install")
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
lbin, ok := ls.Get(1).(lua.LString)
|
||
|
if !ok {
|
||
|
ls.RaiseError("Argument 1 is not a string")
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
s.Builder.Binaries = append(s.Builder.Binaries, lbin.String())
|
||
|
return 0
|
||
|
}
|