|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/carapace-sh/carapace" |
| 5 | + "github.com/spf13/cobra" |
| 6 | +) |
| 7 | + |
| 8 | +var rootCmd = &cobra.Command{ |
| 9 | + Use: "sed", |
| 10 | + Short: "stream editor", |
| 11 | + Long: "https://manpage.me/?sed", |
| 12 | + Run: func(cmd *cobra.Command, args []string) {}, |
| 13 | +} |
| 14 | + |
| 15 | +func Execute() error { |
| 16 | + return rootCmd.Execute() |
| 17 | +} |
| 18 | +func init() { |
| 19 | + carapace.Gen(rootCmd).Standalone() |
| 20 | + |
| 21 | + rootCmd.Flags().BoolS("E", "E", false, "Interpret regular expressions as extended regular expressions") |
| 22 | + rootCmd.Flags().BoolS("H", "H", false, "Enable enhanced features in the regular expression syntax") |
| 23 | + rootCmd.Flags().StringS("I", "I", "", "Edit files in-place, saving backups with the specified extension") |
| 24 | + rootCmd.Flags().BoolS("a", "a", false, "Create or truncate files before any processing begins") |
| 25 | + rootCmd.Flags().StringS("e", "e", "", "Append the editing commands specified by the command argument to the list of commands") |
| 26 | + rootCmd.Flags().StringS("f", "f", "", "Append the editing commands found in the file command_file to the list of commands") |
| 27 | + rootCmd.Flags().StringS("i", "i", "", "Edit files in-place similarly to -I, but treat each file independently from other files") |
| 28 | + rootCmd.Flags().BoolS("l", "l", false, "Make output line buffered") |
| 29 | + rootCmd.Flags().BoolS("n", "n", false, "Suppress output") |
| 30 | + rootCmd.Flags().BoolS("r", "r", false, "Same as -E for compatibility with GNU sed") |
| 31 | + rootCmd.Flags().BoolS("u", "u", false, "Make output unbuffered") |
| 32 | + |
| 33 | + carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ |
| 34 | + "f": carapace.ActionFiles(), |
| 35 | + }) |
| 36 | + |
| 37 | + carapace.Gen(rootCmd).PositionalCompletion( |
| 38 | + carapace.ActionCallback(func(c carapace.Context) carapace.Action { |
| 39 | + if rootCmd.Flag("e").Changed || rootCmd.Flag("f").Changed { |
| 40 | + return carapace.ActionFiles() |
| 41 | + } else { |
| 42 | + return carapace.ActionValues() |
| 43 | + } |
| 44 | + }), |
| 45 | + ) |
| 46 | + |
| 47 | + carapace.Gen(rootCmd).PositionalAnyCompletion(carapace.ActionFiles()) |
| 48 | +} |
0 commit comments