MCPcopy Index your code
hub / github.com/celer-pkg/celer / registerRunCommand

Method registerRunCommand

completion/powershell.go:178–211  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

176}
177
178func (p powershell) registerRunCommand() error {
179 // Install completion file to `~/Documents/WindowsPowerShell/Modules`
180 modulesDir := filepath.Join(os.Getenv("USERPROFILE"), "Documents", "WindowsPowerShell", "Modules")
181 profilePath := filepath.Join(filepath.Dir(modulesDir), "profile.ps1")
182
183 // Append completion file path to profile.
184 if fileio.PathExists(profilePath) {
185 // Add completion script to if not contains.
186 profile, err := os.OpenFile(profilePath, os.O_CREATE|os.O_RDWR, os.ModePerm)
187 if err != nil {
188 return fmt.Errorf("failed to open or create PowerShell profile -> %w", err)
189 }
190 defer profile.Close()
191
192 // Read profile content.
193 content, err := os.ReadFile(profilePath)
194 if err != nil {
195 return fmt.Errorf("failed to read PowerShell profile -> %w", err)
196 }
197
198 lines := strings.Split(string(content), "\n")
199
200 // Add completion script to profile if not contains.
201 if !slices.Contains(lines, p.registerBinary) {
202 profile.WriteString(p.registerBinary + "\n")
203 }
204 } else {
205 if err := os.WriteFile(profilePath, []byte(p.registerBinary), os.ModePerm); err != nil {
206 return fmt.Errorf("failed to write PowerShell profile -> %w", err)
207 }
208 }
209
210 return nil
211}
212
213func (p powershell) unregisterRunCommand() error {
214 // Remove celer_completion.ps1 from profile.ps1.

Callers 1

RegisterMethod · 0.95

Calls 2

PathExistsFunction · 0.92
WriteFileMethod · 0.80

Tested by

no test coverage detected