github.com/Benchkram/bob@v0.0.0-20220321080157-7c8f3876e225/pkg/add/add.go (about)

     1  package add
     2  
     3  import (
     4  	"github.com/Benchkram/bob/bob"
     5  	"github.com/Benchkram/errz"
     6  )
     7  
     8  type AddParams struct {
     9  	repoUrl string
    10  	plain   bool
    11  }
    12  
    13  type Option func(a *AddParams)
    14  
    15  func WithPlainProtocol(explicit bool) Option {
    16  	return func(a *AddParams) {
    17  		a.plain = explicit
    18  	}
    19  }
    20  
    21  func Add(repoURL string, opts ...Option) (err error) {
    22  	defer errz.Recover(&err)
    23  
    24  	bob, err := bob.Bob(bob.WithRequireBobConfig())
    25  	errz.Fatal(err)
    26  
    27  	params := &AddParams{
    28  		repoUrl: repoURL,
    29  		plain:   false,
    30  	}
    31  
    32  	for _, opt := range opts {
    33  		if opt == nil {
    34  			continue
    35  		}
    36  		opt(params)
    37  	}
    38  
    39  	err = bob.Add(params.repoUrl, params.plain)
    40  	errz.Fatal(err)
    41  
    42  	return nil
    43  }