Files
opencloud/ocis/pkg/command/run.go
Michael Barz 5f500d3c06 Apply suggestions from code review
Co-authored-by: Martin <github@diemattels.at>
2022-04-08 20:52:32 +02:00

57 lines
1.3 KiB
Go

package command
import (
"fmt"
"log"
"net"
"net/rpc"
"os"
cli "github.com/urfave/cli/v2"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis/pkg/register"
)
// RunCommand is the entrypoint for the run command.
func RunCommand(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "run",
Usage: "run an extension by name in the runtime (supervised mode)",
Category: "runtime",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "hostname",
Value: "localhost",
EnvVars: []string{"OCIS_RUNTIME_HOST"},
Destination: &cfg.Runtime.Host,
},
&cli.StringFlag{
Name: "port",
Value: "9250",
EnvVars: []string{"OCIS_RUNTIME_PORT"},
Destination: &cfg.Runtime.Port,
},
},
Action: func(c *cli.Context) error {
client, err := rpc.DialHTTP("tcp", net.JoinHostPort(cfg.Runtime.Host, cfg.Runtime.Port))
if err != nil {
log.Fatalf("Failed to connect to the runtime. Has the runtime been started and did you configure the right runtime address (\"%s\")", cfg.Runtime.Host+":"+cfg.Runtime.Port)
}
var reply int
if err := client.Call("Service.Start", os.Args[2], &reply); err != nil {
log.Fatal(err)
}
fmt.Println(reply)
return nil
},
}
}
func init() {
register.AddCommand(RunCommand)
}