goc/cmd/service.go

75 lines
2.1 KiB
Go
Raw Normal View History

2021-09-02 09:48:11 +00:00
/*
Copyright 2021 Qiniu Cloud (qiniu.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2021-07-12 08:39:16 +00:00
package cmd
import (
2024-11-19 03:32:10 +00:00
"github.com/ar0c/goc/v2/pkg/client"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
2021-07-12 08:39:16 +00:00
)
var listCmd = &cobra.Command{
2024-11-19 03:32:10 +00:00
Use: "service",
Short: "Deal with the registered services",
Long: `It can be used to list, remove the registered services.
2021-09-10 03:20:05 +00:00
For disconnected services, remove will delete these serivces forever,
for connected services remove will force these services register again.`,
2021-07-12 08:39:16 +00:00
}
var (
2024-11-19 03:32:10 +00:00
listHost string
listWide bool
listIds []string
listJson bool
)
2021-07-12 12:09:45 +00:00
2021-07-12 08:39:16 +00:00
func init() {
2021-09-10 03:20:05 +00:00
2024-11-19 03:32:10 +00:00
add1Flags := func(f *pflag.FlagSet) {
f.StringVar(&listHost, "host", "127.0.0.1:7777", "specify the host of the goc server")
f.BoolVar(&listWide, "wide", false, "list all services with more information (such as pid)")
f.BoolVar(&listJson, "json", false, "list all services info as json format")
f.StringSliceVar(&listIds, "id", nil, "specify the ids of the services")
}
2021-09-10 03:20:05 +00:00
2024-11-19 03:32:10 +00:00
add1Flags(getServiceCmd.Flags())
add1Flags(deleteServiceCmd.Flags())
2024-11-19 03:32:10 +00:00
listCmd.AddCommand(getServiceCmd)
listCmd.AddCommand(deleteServiceCmd)
rootCmd.AddCommand(listCmd)
2021-07-12 08:39:16 +00:00
}
func list(cmd *cobra.Command, args []string) {
2024-11-19 03:32:10 +00:00
client.ListAgents(listHost, listIds, listWide, listJson)
}
var getServiceCmd = &cobra.Command{
2024-11-19 03:32:10 +00:00
Use: "get",
Run: getAgents,
}
func getAgents(cmd *cobra.Command, args []string) {
2024-11-19 03:32:10 +00:00
client.ListAgents(listHost, listIds, listWide, listJson)
}
var deleteServiceCmd = &cobra.Command{
2024-11-19 03:32:10 +00:00
Use: "delete",
Run: deleteAgents,
}
func deleteAgents(cmd *cobra.Command, args []string) {
2024-11-19 03:32:10 +00:00
client.DeleteAgents(listHost, listIds)
2021-07-12 08:39:16 +00:00
}