github.com/supabase/cli@v1.168.1/internal/db/branch/list/list.go (about)

     1  package list
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"os"
     7  	"path/filepath"
     8  
     9  	"github.com/go-errors/errors"
    10  	"github.com/spf13/afero"
    11  	"github.com/supabase/cli/internal/utils"
    12  )
    13  
    14  func Run(fsys afero.Fs, out io.Writer) error {
    15  	branches, err := afero.ReadDir(fsys, filepath.Dir(utils.CurrBranchPath))
    16  	if errors.Is(err, os.ErrNotExist) {
    17  		return nil
    18  	} else if err != nil {
    19  		return err
    20  	}
    21  
    22  	currBranch, _ := utils.GetCurrentBranchFS(fsys)
    23  	for _, branch := range branches {
    24  		if branch.Name() == filepath.Base(utils.CurrBranchPath) {
    25  			continue
    26  		}
    27  
    28  		if branch.Name() == currBranch {
    29  			fmt.Fprintln(out, "*", branch.Name())
    30  		} else {
    31  			fmt.Fprintln(out, " ", branch.Name())
    32  		}
    33  	}
    34  
    35  	return nil
    36  }