MCPcopy Index your code
hub / github.com/devspace-sh/devspace / SetPluginCommand

Function SetPluginCommand

pkg/devspace/plugin/hook.go:81–128  ·  view source on GitHub ↗
(cobraCmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

79var commandOnce sync.Once
80
81func SetPluginCommand(cobraCmd *cobra.Command, args []string) {
82 commandOnce.Do(func() {
83 pluginContextLock.Lock()
84 defer pluginContextLock.Unlock()
85
86 if cobraCmd == nil {
87 return
88 }
89
90 osArgsBytes, err := json.Marshal(os.Args)
91 if err != nil {
92 logErrorf("marshal os args: %v", err)
93 return
94 }
95
96 pluginContext[CommandEnv] = cobraCmd.Use
97 pluginContext[CommandLineEnv] = cobraCmd.UseLine()
98 pluginContext[OsArgsEnv] = string(osArgsBytes)
99
100 // Flags
101 flags := []string{}
102 cobraCmd.Flags().Visit(func(f *pflag.Flag) {
103 flags = append(flags, "--"+f.Name)
104 flags = append(flags, f.Value.String())
105 })
106 if len(flags) > 0 {
107 flagsStr, err := json.Marshal(flags)
108 if err != nil {
109 logErrorf("marshal flags: %v", err)
110 return
111 }
112
113 pluginContext[CommandFlagsEnv] = string(flagsStr)
114 }
115
116 // Args
117 if len(args) > 0 {
118 argsStr, err := json.Marshal(args)
119 if err != nil {
120 logErrorf("marshal args: %v", err)
121 return
122 }
123 if string(argsStr) != "" {
124 pluginContext[CommandArgsEnv] = string(argsStr)
125 }
126 }
127 })
128}
129
130var configOnce sync.Once
131

Callers 15

NewLogsCmdFunction · 0.92
NewEnterCmdFunction · 0.92
NewAttachCmdFunction · 0.92
RunMethod · 0.92
NewRestartCmdFunction · 0.92
NewInitCmdFunction · 0.92
NewSyncCmdFunction · 0.92
NewAnalyzeCmdFunction · 0.92
NewOpenCmdFunction · 0.92
NewPrintCmdFunction · 0.92
NewRunCmdFunction · 0.92
NewUpgradeCmdFunction · 0.92

Calls 4

logErrorfFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected