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

Function NewCmdAlias

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

Source from the content-addressed store, hash-verified

51}
52
53func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
54 cmd := &cobra.Command{
55 Use: aliasName,
56 Short: fmt.Sprintf("Alias for %q", text.Truncate(80, aliasValue)),
57 RunE: func(c *cobra.Command, args []string) error {
58 expandedArgs, err := expandAlias(aliasValue, args)
59 if err != nil {
60 return err
61 }
62 root := c.Root()
63 root.SetArgs(expandedArgs)
64 return root.Execute()
65 },
66 GroupID: "alias",
67 DisableFlagParsing: true,
68 Annotations: map[string]string{
69 aliasExpansionAnnotation: aliasValue,
70 },
71 }
72 cmdutil.DisableAuthCheck(cmd)
73 // Aliases are user-defined names and must not be reported as telemetry
74 // dimensions, since the name itself may be sensitive (e.g. project or
75 // organization names).
76 cmdutil.DisableTelemetry(cmd)
77 return cmd
78}
79
80// ExpandAlias processes argv to see if it should be rewritten according to a user's aliases.
81func expandAlias(expansion string, args []string) ([]string, error) {

Callers 2

NewCmdRootFunction · 0.70

Calls 4

TruncateFunction · 0.92
DisableAuthCheckFunction · 0.92
DisableTelemetryFunction · 0.92
expandAliasFunction · 0.85

Tested by 1