MCPcopy
hub / github.com/spacecloud-io/space-cloud / GetSubCommands

Function GetSubCommands

space-cli/cmd/modules/logs/commands.go:12–101  ·  view source on GitHub ↗

GetSubCommands is the list of commands the log module expose

()

Source from the content-addressed store, hash-verified

10
11// GetSubCommands is the list of commands the log module expose
12func GetSubCommands() []*cobra.Command {
13 var getServiceLogs = &cobra.Command{
14 Use: "logs [replica-id]",
15 Example: "1) space-cli logs service1--v1 --project myproject --follow\n2) space-cli logs service1--v1 --project myproject --follow --task-id greeting",
16 PreRun: func(cmd *cobra.Command, args []string) {
17 err := viper.BindPFlag("project", cmd.Flags().Lookup("project"))
18 if err != nil {
19 _ = utils.LogError("Unable to bind the flag ('project')", nil)
20 }
21 err = viper.BindPFlag("task-id", cmd.Flags().Lookup("task-id"))
22 if err != nil {
23 _ = utils.LogError("Unable to bind the flag ('task-id')", nil)
24 }
25 err = viper.BindPFlag("follow", cmd.Flags().Lookup("follow"))
26 if err != nil {
27 _ = utils.LogError("Unable to bind the flag ('follow')", nil)
28 }
29 err = viper.BindPFlag("since", cmd.Flags().Lookup("since"))
30 if err != nil {
31 _ = utils.LogError("Unable to bind the flag ('since')", nil)
32 }
33 err = viper.BindPFlag("since-time", cmd.Flags().Lookup("since-time"))
34 if err != nil {
35 _ = utils.LogError("Unable to bind the flag ('since-time')", nil)
36 }
37 err = viper.BindPFlag("tail", cmd.Flags().Lookup("tail"))
38 if err != nil {
39 _ = utils.LogError("Unable to bind the flag ('tail')", nil)
40 }
41 },
42 RunE: actionGetServiceLogs,
43 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
44 if len(args) == 0 {
45 project, check := utils.GetProjectID()
46 if !check {
47 utils.LogDebug("Project not specified in flag", nil)
48 return nil, cobra.ShellCompDirectiveDefault
49 }
50 replicaIDs, err := getServiceStatus(project, "service-status", map[string]string{})
51 if err != nil {
52 utils.LogDebug("Unable to get service status", map[string]interface{}{"error": err})
53 return nil, cobra.ShellCompDirectiveDefault
54 }
55 return replicaIDs, cobra.ShellCompDirectiveDefault
56 }
57 return nil, cobra.ShellCompDirectiveDefault
58 },
59 }
60
61 getServiceLogs.Flags().StringP("task-id", "", "", "The unique id for the task")
62 getServiceLogs.Flags().BoolP("follow", "", false, "Follow log output")
63 getServiceLogs.Flags().StringP("since", "", "", "Only return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to all logs. Only one of\nsince-time / since may be used.")
64 getServiceLogs.Flags().StringP("since-time", "", "", "Only return logs after a specific date (RFC3339). Defaults to all logs. Only one of since-time /\nsince may be used.")
65 getServiceLogs.Flags().StringP("tail", "", "", "Lines of recent log file to display. Defaults to -1 with no selector, showing all log lines otherwise")
66
67 if err := getServiceLogs.RegisterFlagCompletionFunc("task-id", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
68 project, check := utils.GetProjectID()
69 if !check {

Callers

nothing calls this directly

Calls 3

getServiceStatusFunction · 0.85
GetProjectIDMethod · 0.80
GetServicesMethod · 0.65

Tested by

no test coverage detected