MCPcopy Index your code
hub / github.com/cli/cli / NewCmdCopilot

Function NewCmdCopilot

pkg/cmd/copilot/copilot.go:41–131  ·  view source on GitHub ↗
(f *cmdutil.Factory, telemetry ghtelemetry.CommandRecorder, runF func(*CopilotOptions) error)

Source from the content-addressed store, hash-verified

39}
40
41func NewCmdCopilot(f *cmdutil.Factory, telemetry ghtelemetry.CommandRecorder, runF func(*CopilotOptions) error) *cobra.Command {
42 opts := &CopilotOptions{
43 IO: f.IOStreams,
44 HttpClient: f.HttpClient,
45 Prompter: f.Prompter,
46 }
47
48 cmd := &cobra.Command{
49 Use: "copilot [flags] [args]",
50 Short: "Run the GitHub Copilot CLI (preview)",
51 Long: heredoc.Docf(`
52 Runs the GitHub Copilot CLI.
53
54 Executing the Copilot CLI through %[1]sgh%[1]s is currently in preview and subject to change.
55
56 If already installed, %[1]sgh%[1]s will execute the Copilot CLI found in your %[1]sPATH%[1]s.
57 If the Copilot CLI is not installed, it will be downloaded to %[2]s.
58
59 Use %[1]s--remove%[1]s to remove the downloaded Copilot CLI.
60
61 This command is only supported on Windows, Linux, and Darwin, on amd64/x64
62 or arm64 architectures.
63
64 To prevent %[1]sgh%[1]s from interpreting flags intended for Copilot,
65 use %[1]s--%[1]s before Copilot flags and args.
66
67 Learn more at https://gh.io/copilot-cli
68 `, "`", copilotInstallDir()),
69 Example: heredoc.Doc(`
70 # Download and run the Copilot CLI
71 $ gh copilot
72
73 # Run the Copilot CLI
74 $ gh copilot -p "Summarize this week's commits" --allow-tool 'shell(git)'
75
76 # Remove the Copilot CLI (if installed through gh)
77 $ gh copilot --remove
78
79 # Run the Copilot CLI help command
80 $ gh copilot -- --help
81 `),
82 DisableFlagParsing: true,
83 RunE: func(cmd *cobra.Command, args []string) error {
84 telemetry.SetSampleRate(ghtelemetry.SAMPLE_ALL)
85
86 stopParsePos := -1
87 for i, arg := range args {
88 if arg == "--" {
89 stopParsePos = i
90 break
91 }
92 }
93
94 ghArgs := args
95 opts.CopilotArgs = args
96 if stopParsePos >= 0 {
97 ghArgs = args[:stopParsePos]
98 opts.CopilotArgs = args[stopParsePos+1:] // +1 to skip the "--" itself

Callers 2

TestNewCmdCopilotFunction · 0.85

Calls 6

FlagErrorfFunction · 0.92
DisableAuthCheckFunction · 0.92
copilotInstallDirFunction · 0.85
runCopilotFunction · 0.85
ContainsMethod · 0.80
SetSampleRateMethod · 0.65

Tested by 2

TestNewCmdCopilotFunction · 0.68