github.com/jenkins-x/jx/v2@v2.1.155/pkg/cmd/step/git/step_git_close.go (about) 1 package git 2 3 import ( 4 "github.com/jenkins-x/jx/v2/pkg/cmd/helper" 5 "github.com/jenkins-x/jx/v2/pkg/cmd/opts" 6 "github.com/jenkins-x/jx/v2/pkg/cmd/opts/step" 7 "github.com/jenkins-x/jx/v2/pkg/cmd/templates" 8 "github.com/pkg/errors" 9 "github.com/spf13/cobra" 10 ) 11 12 // StepGitCloseOptions contains the command line flags 13 type StepGitCloseOptions struct { 14 step.StepOptions 15 Dir string 16 Orgs []string 17 Excludes []string 18 Includes []string 19 DryRun bool 20 } 21 22 var ( 23 // StepGitCloseLong command long description 24 StepGitCloseLong = templates.LongDesc(` 25 This pipeline step will close git provider issue trackers, wikis and projects that are not in use 26 (no issues, no wiki pages, no projects). It will log any it can't close, indicating why. 27 28 `) 29 // StepGitCloseExample command example 30 StepGitCloseExample = templates.Examples(` 31 # Close unused issue trackers, wikis and projects for organizations 32 jx step git close --org https://github.com/jenkins-x --org https://github.com/jenkins-x 33 34 # Close unused issue trackers, wikis and projects for an organization 35 jx step git close --org https://github.com/jenkins-x --include jenkins-x/jx 36 37 `) 38 ) 39 40 // NewCmdStepGitClose create the 'step git envs' command 41 func NewCmdStepGitClose(commonOpts *opts.CommonOptions) *cobra.Command { 42 options := StepGitCloseOptions{ 43 StepOptions: step.StepOptions{ 44 CommonOptions: commonOpts, 45 }, 46 } 47 cmd := &cobra.Command{ 48 Use: "close", 49 Short: "Closes issue trackers, wikis and projects", 50 Long: StepGitCloseLong, 51 Example: StepGitCloseExample, 52 Run: func(cmd *cobra.Command, args []string) { 53 options.Cmd = cmd 54 options.Args = args 55 err := options.Run() 56 helper.CheckErr(err) 57 }, 58 } 59 60 cmd.Flags().StringVarP(&options.Dir, "dir", "", "", "The directory in which the git repo is checked out, by default the working directory") 61 cmd.Flags().StringArrayVarP(&options.Orgs, "org", "", make([]string, 0), "An org to close issue trackers, wikis and projects for") 62 cmd.Flags().StringArrayVarP(&options.Excludes, "exclude", "", make([]string, 0), "A repo to ignore when closing issue trackers, wikis and projects e.g. jenkins-x/jx") 63 cmd.Flags().StringArrayVarP(&options.Includes, "include", "", make([]string, 0), "If any includes are specified then only those repos will have issue trackers, wikis and projects closed") 64 cmd.Flags().BoolVarP(&options.DryRun, "dry-run", "", false, "execute as a dry run - print what would be done but exit before making any changes") 65 cmd.Flags().BoolVarP(&options.BatchMode, opts.OptionBatchMode, "b", false, "execute in batch mode") 66 return cmd 67 } 68 69 // Run implements the command 70 func (o *StepGitCloseOptions) Run() error { 71 if len(o.Orgs) == 0 { 72 return o.Cmd.Help() 73 } 74 err := o.DisableFeatures(o.Orgs, o.Includes, o.Excludes, o.DryRun) 75 if err != nil { 76 return errors.WithStack(err) 77 } 78 return nil 79 }