| 26 | } |
| 27 | |
| 28 | func NewCmdUnarchive(f *cmdutil.Factory, runF func(*UnarchiveOptions) error) *cobra.Command { |
| 29 | opts := &UnarchiveOptions{ |
| 30 | IO: f.IOStreams, |
| 31 | HttpClient: f.HttpClient, |
| 32 | Config: f.Config, |
| 33 | BaseRepo: f.BaseRepo, |
| 34 | Prompter: f.Prompter, |
| 35 | } |
| 36 | |
| 37 | cmd := &cobra.Command{ |
| 38 | Use: "unarchive [<repository>]", |
| 39 | Short: "Unarchive a repository", |
| 40 | Long: heredoc.Doc(`Unarchive a GitHub repository. |
| 41 | |
| 42 | With no argument, unarchives the current repository.`), |
| 43 | Args: cobra.MaximumNArgs(1), |
| 44 | RunE: func(cmd *cobra.Command, args []string) error { |
| 45 | if len(args) > 0 { |
| 46 | opts.RepoArg = args[0] |
| 47 | } |
| 48 | |
| 49 | if !opts.Confirmed && !opts.IO.CanPrompt() { |
| 50 | return cmdutil.FlagErrorf("--yes required when not running interactively") |
| 51 | } |
| 52 | |
| 53 | if runF != nil { |
| 54 | return runF(opts) |
| 55 | } |
| 56 | |
| 57 | return unarchiveRun(opts) |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | cmd.Flags().BoolVar(&opts.Confirmed, "confirm", false, "Skip the confirmation prompt") |
| 62 | _ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead") |
| 63 | cmd.Flags().BoolVarP(&opts.Confirmed, "yes", "y", false, "Skip the confirmation prompt") |
| 64 | return cmd |
| 65 | } |
| 66 | |
| 67 | func unarchiveRun(opts *UnarchiveOptions) error { |
| 68 | cs := opts.IO.ColorScheme() |