()
| 91 | } |
| 92 | |
| 93 | func (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 | |
| 123 | func (b bash) uninstallCompletion() error { |
| 124 | destination := filepath.Join(b.homeDir, ".local", "share", "bash-completion", "completions", "celer") |
no test coverage detected