github.com/grahambrereton-form3/tilt@v0.10.18/internal/tiltfile/git/repo.go (about)

     1  package git
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"path/filepath"
     7  
     8  	"go.starlark.net/starlark"
     9  
    10  	"github.com/windmilleng/tilt/internal/tiltfile/starkit"
    11  	"github.com/windmilleng/tilt/internal/tiltfile/value"
    12  )
    13  
    14  type Repo struct {
    15  	basePath string
    16  }
    17  
    18  var _ starlark.Value = &Repo{}
    19  
    20  func (gr *Repo) String() string {
    21  	return fmt.Sprintf("[git.Repo] '%v'", gr.basePath)
    22  }
    23  
    24  func (gr *Repo) Type() string {
    25  	return "git.Repo"
    26  }
    27  
    28  func (gr *Repo) Freeze() {}
    29  
    30  func (gr *Repo) Truth() starlark.Bool {
    31  	return gr.basePath != ""
    32  }
    33  
    34  func (*Repo) Hash() (uint32, error) {
    35  	return 0, errors.New("unhashable type: git.Repo")
    36  }
    37  
    38  func (gr *Repo) Attr(name string) (starlark.Value, error) {
    39  	switch name {
    40  	case "paths":
    41  		return starlark.NewBuiltin(name, gr.path), nil
    42  	default:
    43  		return nil, nil
    44  	}
    45  
    46  }
    47  
    48  func (gr *Repo) AttrNames() []string {
    49  	return []string{"paths"}
    50  }
    51  
    52  func (gr *Repo) path(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
    53  	var path string
    54  	err := starkit.UnpackArgs(thread, fn.Name(), args, kwargs, "paths", &path)
    55  	if err != nil {
    56  		return nil, err
    57  	}
    58  
    59  	return starlark.String(gr.MakeLocalPath(path)), nil
    60  }
    61  
    62  func (gr *Repo) MakeLocalPath(path string) string {
    63  	return filepath.Join(gr.basePath, path)
    64  }
    65  
    66  var _ value.PathMaker = &Repo{}