MCPcopy
hub / github.com/cli/cli / NewCmdLink

Function NewCmdLink

pkg/cmd/project/link/link.go:40–110  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(config linkConfig) error)

Source from the content-addressed store, hash-verified

38}
39
40func NewCmdLink(f *cmdutil.Factory, runF func(config linkConfig) error) *cobra.Command {
41 opts := linkOpts{}
42 linkCmd := &cobra.Command{
43 Short: "Link a project to a repository or a team",
44 Use: "link [<number>]",
45 Example: heredoc.Doc(`
46 # Link monalisa's project 1 to her repository "my_repo"
47 $ gh project link 1 --owner monalisa --repo my_repo
48
49 # Link monalisa's organization's project 1 to her team "my_team"
50 $ gh project link 1 --owner my_organization --team my_team
51
52 # Link monalisa's project 1 to the repository of current directory if neither --repo nor --team is specified
53 $ gh project link 1
54 `),
55 RunE: func(cmd *cobra.Command, args []string) error {
56 client, err := client.New(f)
57 if err != nil {
58 return err
59 }
60
61 if len(args) == 1 {
62 num, err := strconv.ParseInt(args[0], 10, 32)
63 if err != nil {
64 return cmdutil.FlagErrorf("invalid number: %v", args[0])
65 }
66 opts.number = int32(num)
67 }
68
69 if opts.repo == "" && opts.team == "" {
70 repo, err := f.BaseRepo()
71 if err != nil {
72 return err
73 }
74 opts.repo = repo.RepoName()
75 if opts.owner == "" {
76 opts.owner = repo.RepoOwner()
77 }
78 }
79
80 if err := cmdutil.MutuallyExclusive("specify only one of `--repo` or `--team`", opts.repo != "", opts.team != ""); err != nil {
81 return err
82 }
83
84 if err = validateRepoOrTeamFlag(&opts); err != nil {
85 return err
86 }
87
88 config := linkConfig{
89 httpClient: f.HttpClient,
90 config: f.Config,
91 client: client,
92 opts: opts,
93 io: f.IOStreams,
94 }
95
96 // allow testing of the command without actually running it
97 if runF != nil {

Callers 1

TestNewCmdLinkFunction · 0.85

Calls 9

NewFunction · 0.92
FlagErrorfFunction · 0.92
MutuallyExclusiveFunction · 0.92
EnableRepoOverrideFunction · 0.92
runLinkFunction · 0.85
validateRepoOrTeamFlagFunction · 0.70
BaseRepoMethod · 0.65
RepoNameMethod · 0.65
RepoOwnerMethod · 0.65

Tested by 1

TestNewCmdLinkFunction · 0.68