(io *iostreams.IOStreams, aliasName, aliasValue string)
| 18 | ) |
| 19 | |
| 20 | func NewCmdShellAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command { |
| 21 | cmd := &cobra.Command{ |
| 22 | Use: aliasName, |
| 23 | Short: fmt.Sprintf("Shell alias for %q", text.Truncate(80, aliasValue)), |
| 24 | RunE: func(c *cobra.Command, args []string) error { |
| 25 | expandedArgs, err := expandShellAlias(aliasValue, args, nil) |
| 26 | if err != nil { |
| 27 | return err |
| 28 | } |
| 29 | externalCmd := exec.Command(expandedArgs[0], expandedArgs[1:]...) |
| 30 | externalCmd.Stderr = io.ErrOut |
| 31 | externalCmd.Stdout = io.Out |
| 32 | externalCmd.Stdin = io.In |
| 33 | preparedCmd := run.PrepareCmd(externalCmd) |
| 34 | if err = preparedCmd.Run(); err != nil { |
| 35 | var execError *exec.ExitError |
| 36 | if errors.As(err, &execError) { |
| 37 | return &ExternalCommandExitError{execError} |
| 38 | } |
| 39 | return fmt.Errorf("failed to run external command: %w\n", err) |
| 40 | } |
| 41 | return nil |
| 42 | }, |
| 43 | GroupID: "alias", |
| 44 | DisableFlagParsing: true, |
| 45 | } |
| 46 | cmdutil.DisableAuthCheck(cmd) |
| 47 | // Aliases are user-defined names and must not be reported as telemetry |
| 48 | // dimensions, since the name itself may be sensitive (e.g. project or |
| 49 | // organization names). |
| 50 | cmdutil.DisableTelemetry(cmd) |
| 51 | return cmd |
| 52 | } |
| 53 | |
| 54 | func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command { |
| 55 | cmd := &cobra.Command{ |
no test coverage detected