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

Function NewCmdAlias

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

Source from the content-addressed store, hash-verified

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