MCPcopy
hub / github.com/cli/cli / NewCmdShellAlias

Function NewCmdShellAlias

pkg/cmd/root/alias.go:20–52  ·  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 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
54func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
55 cmd := &cobra.Command{

Callers 1

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

no test coverage detected