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

Function NewCmdCopilot

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

Source from the content-addressed store, hash-verified

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

Callers 1

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 1

TestNewCmdCopilotFunction · 0.68