MCPcopy Create free account
hub / github.com/cli/cli / NewCmdShellAlias

Function NewCmdShellAlias

pkg/cmd/root/alias.go:20–51  ·  view source on GitHub ↗
(io *iostreams.IOStreams, aliasName, aliasValue string)

Source from the content-addressed store, hash-verified

18)
19
20func 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 if execError, ok := errors.AsType[*exec.ExitError](err); ok {
36 return &ExternalCommandExitError{execError}
37 }
38 return fmt.Errorf("failed to run external command: %w\n", err)
39 }
40 return nil
41 },
42 GroupID: "alias",
43 DisableFlagParsing: true,
44 }
45 cmdutil.DisableAuthCheck(cmd)
46 // Aliases are user-defined names and must not be reported as telemetry
47 // dimensions, since the name itself may be sensitive (e.g. project or
48 // organization names).
49 cmdutil.DisableTelemetry(cmd)
50 return cmd
51}
52
53func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
54 cmd := &cobra.Command{

Callers 2

NewCmdRootFunction · 0.85

Calls 7

TruncateFunction · 0.92
DisableAuthCheckFunction · 0.92
DisableTelemetryFunction · 0.92
expandShellAliasFunction · 0.85
CommandMethod · 0.80
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by 1