MCPcopy Create free account
hub / github.com/celer-pkg/celer / installCompletion

Method installCompletion

completion/bash.go:93–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

91}
92
93func (b bash) installCompletion() error {
94 if err := dirs.CleanTmpFilesDir(); err != nil {
95 return fmt.Errorf("failed to clean tmp files dir -> %w", err)
96 }
97
98 // Generate completion file.
99 filePath := filepath.Join(dirs.TmpFilesDir, "celer")
100 file, err := os.Create(filePath)
101 if err != nil {
102 return fmt.Errorf("failed to create bash completion file -> %w", err)
103 }
104 defer file.Close()
105
106 if err := b.rootCmd.GenBashCompletion(file); err != nil {
107 return fmt.Errorf("failed to generate bash completion file -> %w", err)
108 }
109
110 // Install completion file to `~/.local/share/bash-completion/completions`
111 destination := filepath.Join(b.homeDir, ".local", "share", "bash-completion", "completions", "celer")
112 if err := os.MkdirAll(filepath.Dir(destination), os.ModePerm); err != nil {
113 return err
114 }
115 if err := fileio.MoveFile(filePath, destination); err != nil {
116 return err
117 }
118
119 fmt.Printf("[integrate] completion -> %s\n", destination)
120 return nil
121}
122
123func (b bash) uninstallCompletion() error {
124 destination := filepath.Join(b.homeDir, ".local", "share", "bash-completion", "completions", "celer")

Callers 1

RegisterMethod · 0.95

Calls 3

CleanTmpFilesDirFunction · 0.92
MoveFileFunction · 0.92
MkdirAllMethod · 0.80

Tested by

no test coverage detected