From 3967812bd0de40330dfbb9e1a7d14d4073cc1b10 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 12 Dec 2016 15:50:03 +0100 Subject: examples: review, testing and documentation (#176) * examples reviews, testing and documentation * including the execution on travis, and fix readme * fix example link * including the execution on travis --- examples/storage/main.go | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) (limited to 'examples/storage/main.go') diff --git a/examples/storage/main.go b/examples/storage/main.go index d85f8e9..b047e43 100644 --- a/examples/storage/main.go +++ b/examples/storage/main.go @@ -6,29 +6,29 @@ import ( "strings" "gopkg.in/src-d/go-git.v4" + . "gopkg.in/src-d/go-git.v4/examples" "gopkg.in/src-d/go-git.v4/examples/storage/aerospike" driver "github.com/aerospike/aerospike-client-go" - "github.com/fatih/color" ) func main() { - checkArgs() + CheckArgs("", "") action := os.Args[1] url := os.Args[2] // Aerospike client to be used by the custom storage client, err := driver.NewClient("127.0.0.1", 3000) - checkIfError(err) + CheckIfError(err) // New instance of the custom aerospike storage, all the objects, // references and configuration is saved to aerospike s, err := aerospike.NewStorage(client, "test", url) - checkIfError(err) + CheckIfError(err) // A new repository instance using as storage the custom implementation r, err := git.NewRepository(s) - checkIfError(err) + CheckIfError(err) switch action { case "clone": @@ -43,24 +43,23 @@ func main() { func clone(r *git.Repository, url string) { // Clone the given repository, all the objects, references and // configuration sush as remotes, are save into the Aerospike database. - // > git clone - color.Blue("git clone %s", url) + Info("git clone %s", url) + err := r.Clone(&git.CloneOptions{URL: url}) - checkIfError(err) + CheckIfError(err) } func log(r *git.Repository) { // Prints the history of the repository starting in the current HEAD, the // objects are retrieved from Aerospike database. - // > git log --oneline - color.Blue("git log --oneline") + Info("git log --oneline") ref, err := r.Head() - checkIfError(err) + CheckIfError(err) commit, err := r.Commit(ref.Hash()) - checkIfError(err) + CheckIfError(err) commits, err := commit.History() - checkIfError(err) + CheckIfError(err) for _, c := range commits { hash := c.Hash.String() @@ -68,19 +67,3 @@ func log(r *git.Repository) { fmt.Println(hash[:7], line[0]) } } - -func checkIfError(err error) { - if err == nil { - return - } - - color.Red("error: %s", err) - os.Exit(1) -} - -func checkArgs() { - if len(os.Args) < 3 { - color.Cyan("Usage: %s ", os.Args[0]) - os.Exit(1) - } -} -- cgit