github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/catalog.go (about)

     1  package alfred
     2  
     3  import (
     4  	"strings"
     5  	"time"
     6  )
     7  
     8  func isCatalog(task string) bool {
     9  	return strings.HasPrefix(task, "@")
    10  }
    11  
    12  func updateCatalog(dir string, context *Context) {
    13  	// catalogs at this point are just git repositories.
    14  	// assume a git repository, and update
    15  	context.lock.Lock()
    16  	_, ok := execute("git pull", dir)
    17  	context.lock.Unlock()
    18  
    19  	// switch the directory
    20  	context.rootDir = dir
    21  
    22  	if ok {
    23  		outOK("@catalog", "updated!", context)
    24  		return
    25  	}
    26  	context.lock.Lock()
    27  	outWarn("@catalog", "Unable to update the catalog. It could be out of date.", context)
    28  	<-time.After(3 * time.Second)
    29  	context.lock.Unlock()
    30  }