MCPcopy Index your code
hub / github.com/opencloud-eu/opencloud / ListCommand

Function ListCommand

opencloud/pkg/command/list.go:19–55  ·  view source on GitHub ↗

ListCommand is the entrypoint for the list command.

(cfg *config.Config)

Source from the content-addressed store, hash-verified

17
18// ListCommand is the entrypoint for the list command.
19func ListCommand(cfg *config.Config) *cobra.Command {
20 listCmd := &cobra.Command{
21 Use: "list",
22 Short: "list OpenCloud services running in the runtime (supervised mode)",
23 PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
24 return configlog.ReturnError(parser.ParseConfig(cfg, true))
25 },
26 RunE: func(cmd *cobra.Command, args []string) error {
27 host := viper.GetString("hostname")
28 port := viper.GetString("port")
29
30 client, err := rpc.DialHTTP("tcp", net.JoinHostPort(host, port))
31 if err != nil {
32 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)
33 }
34
35 var arg1 string
36
37 if err := client.Call("Service.List", struct{}{}, &arg1); err != nil {
38 log.Fatal(err)
39 }
40
41 fmt.Println(arg1)
42
43 return nil
44 },
45 }
46
47 listCmd.Flags().String("hostname", "localhost", "hostname of the runtime")
48 _ = viper.BindEnv("hostname", "OC_RUNTIME_HOST")
49 _ = viper.BindPFlag("hostname", listCmd.Flags().Lookup("hostname"))
50
51 listCmd.Flags().String("port", "9250", "port of the runtime")
52 _ = viper.BindEnv("port", "OC_RUNTIME_PORT")
53 _ = viper.BindPFlag("port", listCmd.Flags().Lookup("port"))
54 return listCmd
55}
56
57func init() {
58 register.AddCommand(ListCommand)

Callers

nothing calls this directly

Calls 4

ReturnErrorFunction · 0.92
ParseConfigFunction · 0.92
FatalfMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected