mirror of https://github.com/Hilbis/Hilbish
refactor(minor): reduce the amount of module renaming
parent
a29eddb1bf
commit
e0cf87d272
16
lua.go
16
lua.go
|
@ -2,12 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
hooks "hilbish/golibs/bait"
|
||||
cmds "hilbish/golibs/commander"
|
||||
"hilbish/golibs/bait"
|
||||
"hilbish/golibs/commander"
|
||||
lfs "hilbish/golibs/fs"
|
||||
"os"
|
||||
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
var minimalconf = `
|
||||
|
@ -32,9 +32,9 @@ func LuaInit(confpath string) {
|
|||
// Add fs module to Lua
|
||||
l.PreloadModule("fs", lfs.Loader)
|
||||
|
||||
commander := cmds.New()
|
||||
cmds := commander.New()
|
||||
// When a command from Lua is added, register it for use
|
||||
commander.Events.On("commandRegister",
|
||||
cmds.Events.On("commandRegister",
|
||||
func(cmdName string, cmd *lua.LFunction) {
|
||||
commands[cmdName] = true
|
||||
l.SetField(
|
||||
|
@ -44,10 +44,10 @@ func LuaInit(confpath string) {
|
|||
cmd)
|
||||
})
|
||||
|
||||
l.PreloadModule("commander", commander.Loader)
|
||||
l.PreloadModule("commander", cmds.Loader)
|
||||
|
||||
bait = hooks.New()
|
||||
l.PreloadModule("bait", bait.Loader)
|
||||
hooks = bait.New()
|
||||
l.PreloadModule("bait", hooks.Loader)
|
||||
|
||||
// Add more paths that Lua can require from
|
||||
l.DoString(`package.path = package.path
|
||||
|
|
4
main.go
4
main.go
|
@ -8,7 +8,7 @@ import (
|
|||
"os/user"
|
||||
"strings"
|
||||
|
||||
hooks "hilbish/golibs/bait"
|
||||
"hilbish/golibs/bait"
|
||||
|
||||
"github.com/akamensky/argparse"
|
||||
"github.com/bobappleyard/readline"
|
||||
|
@ -28,7 +28,7 @@ var (
|
|||
commands = map[string]bool{}
|
||||
aliases = map[string]string{}
|
||||
|
||||
bait hooks.Bait
|
||||
hooks bait.Bait
|
||||
homedir string
|
||||
running bool
|
||||
interactive bool
|
||||
|
|
10
shell.go
10
shell.go
|
@ -23,7 +23,7 @@ func RunInput(input string) {
|
|||
// If it succeeds, add to history and prompt again
|
||||
HandleHistory(input)
|
||||
|
||||
bait.Em.Emit("command.exit", 0)
|
||||
hooks.Em.Emit("command.exit", 0)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -71,22 +71,22 @@ func RunInput(input string) {
|
|||
if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") {
|
||||
continue
|
||||
} else if code, ok := interp.IsExitStatus(err); ok {
|
||||
bait.Em.Emit("command.exit", code)
|
||||
hooks.Em.Emit("command.exit", code)
|
||||
} else if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
bait.Em.Emit("command.exit", 1)
|
||||
hooks.Em.Emit("command.exit", 1)
|
||||
}
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if code, ok := interp.IsExitStatus(err); ok {
|
||||
bait.Em.Emit("command.exit", code)
|
||||
hooks.Em.Emit("command.exit", code)
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bait.Em.Emit("command.exit", 0)
|
||||
hooks.Em.Emit("command.exit", 0)
|
||||
}
|
||||
HandleHistory(cmdString)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue