add remote flag to send remote commands to server

Mentioned in #45.
This commit is contained in:
Gokcehan 2016-12-19 21:28:57 +03:00
parent 2085b6d797
commit 0298630114
3 changed files with 13 additions and 5 deletions

View File

@ -146,7 +146,7 @@ func loadFiles() (list []string, copy bool, err error) {
return
}
func sendServer(cmd string) error {
func sendRemote(cmd string) error {
c, err := net.Dial("unix", gSocketPath)
if err != nil {
return fmt.Errorf("dialing to send server: %s", err)

View File

@ -274,7 +274,7 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
app.nav.marks = make(map[string]bool)
if err := sendServer("send sync"); err != nil {
if err := sendRemote("send sync"); err != nil {
msg := fmt.Sprintf("yank: %s", err)
app.ui.message = msg
log.Printf(msg)
@ -287,7 +287,7 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
app.nav.marks = make(map[string]bool)
if err := sendServer("send sync"); err != nil {
if err := sendRemote("send sync"); err != nil {
msg := fmt.Sprintf("delete: %s", err)
app.ui.message = msg
log.Printf(msg)

12
main.go
View File

@ -72,6 +72,7 @@ func startServer() {
func main() {
showDoc := flag.Bool("doc", false, "show documentation")
remoteCmd := flag.String("remote", "", "send remote command to server")
serverMode := flag.Bool("server", false, "start server (automatic)")
cpuprofile := flag.String("cpuprofile", "", "path to the file to write the cpu profile")
flag.StringVar(&gLastDirPath, "last-dir-path", "", "path to the file to write the last dir on exit (to use for cd)")
@ -84,13 +85,20 @@ func main() {
return
}
if *remoteCmd != "" {
if err := sendRemote(*remoteCmd); err != nil {
log.Fatalf("remote command: %s", err)
}
return
}
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal("could not create CPU profile: ", err)
log.Fatalf("could not create CPU profile: %s", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
log.Fatalf("could not start CPU profile: %s", err)
}
defer pprof.StopCPUProfile()
}