| 38 | } |
| 39 | |
| 40 | func NewCmdUnlink(f *cmdutil.Factory, runF func(config unlinkConfig) error) *cobra.Command { |
| 41 | opts := unlinkOpts{} |
| 42 | linkCmd := &cobra.Command{ |
| 43 | Short: "Unlink a project from a repository or a team", |
| 44 | Use: "unlink [<number>]", |
| 45 | Example: heredoc.Doc(` |
| 46 | # Unlink monalisa's project 1 from her repository "my_repo" |
| 47 | $ gh project unlink 1 --owner monalisa --repo my_repo |
| 48 | |
| 49 | # Unlink monalisa's organization's project 1 from her team "my_team" |
| 50 | $ gh project unlink 1 --owner my_organization --team my_team |
| 51 | |
| 52 | # Unlink monalisa's project 1 from the repository of current directory if neither --repo nor --team is specified |
| 53 | $ gh project unlink 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 := unlinkConfig{ |
| 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 { |