Skip to content

Commit

Permalink
preety priting for terminal using colors
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh committed May 18, 2017
1 parent 559c535 commit 8edbad4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
6 changes: 4 additions & 2 deletions cmd/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
log "github.com/Sirupsen/logrus"
term "github.com/appscode/go-term"
"github.com/dinesh/datacol/cmd/stdcli"
"gopkg.in/urfave/cli.v2"
"k8s.io/client-go/pkg/util/validation"
Expand Down Expand Up @@ -55,7 +56,8 @@ func cmdAppRestart(c *cli.Context) error {
return err
}

fmt.Println("Restarted")
term.Successln("RESTARTED")

return nil
}

Expand Down Expand Up @@ -85,7 +87,7 @@ func cmdAppCreate(c *cli.Context) error {

errs := validation.IsDNS1123Label(name)
if len(errs) > 0 {
fmt.Printf("Invalid app name: %s\n", name)
term.Warningln(fmt.Sprintf("Invalid app name: %s", name))
for _, e := range errs {
log.Errorf(e)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/provider/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
log "github.com/Sirupsen/logrus"
term "github.com/appscode/go-term"
"github.com/appscode/go/crypto/rand"
"golang.org/x/oauth2/google"
csm "google.golang.org/api/cloudresourcemanager/v1"
Expand Down Expand Up @@ -154,7 +155,7 @@ func teardown(dmService *dm.Service, name, project string) error {
}

func TeardownStack(name, project, bucket string) error {
log.Infof("Deleting stack %s", name)
term.Printf("Deleting stack %s\n", name)

gsService := storageService(name)
resp, err := gsService.Objects.List(bucket).Do()
Expand Down Expand Up @@ -207,7 +208,7 @@ func resetDatabase(name, project string) error {
}

func waitForDpOp(svc *dm.Service, op *dm.Operation, project string, interrupt bool, teardown func() error) error {
log.Infof("Waiting on %s [%v]", op.OperationType, op.Name)
term.Printf("Waiting on %s [%v]", op.OperationType, op.Name)

cancelCh := make(chan os.Signal, 1)
signal.Notify(cancelCh, os.Interrupt, syscall.SIGTERM)
Expand Down
7 changes: 4 additions & 3 deletions cmd/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
log "github.com/Sirupsen/logrus"
term "github.com/appscode/go-term"
pb "github.com/dinesh/datacol/api/models"
"github.com/dinesh/datacol/cmd/provider/gcp"
"github.com/dinesh/datacol/cmd/stdcli"
Expand Down Expand Up @@ -116,7 +117,7 @@ These credentials will only be used to communicate between this installer runnin
return err
}

fmt.Printf("\nDONE.\n")
term.Successln("\nDONE")

fmt.Printf("Next, create an app with `STACK=%s datacol apps create`.\n", stackName)
return nil
Expand All @@ -127,7 +128,7 @@ func cmdStackDestroy(c *cli.Context) error {
return err
}

fmt.Printf("\nDONE\n")
term.Successln("\nDONE")
return nil
}

Expand Down Expand Up @@ -171,7 +172,7 @@ func initialize(opts *gcp.InitOptions, nodes int, optout bool) error {

fmt.Printf("\nDatacol needs to communicate with various APIs provided by cloud platform, please enable APIs by opening following link in browser and click Continue.\n")
url := fmt.Sprintf("https://console.cloud.google.com/flows/enableapi?apiid=%s&project=%s", strings.Join(apis, ","), opts.Project)
prompt(url)
term.Confirm(url)

res, err := gcp.InitializeStack(opts)
if err != nil {
Expand Down
38 changes: 38 additions & 0 deletions hack/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

set -e
PLATFORM='unknown'
unamestr=`uname`

case "$unamestr" in
'Linux') PLATFORM='linux';;
'Darwin') PLATFORM='osx';;
*);;
esac

if [[ "$PLATFORM" == 'unknown' ]]; then
echo "We don't provide datacol CLI for ${PLATFORM} yet. Please contact at http://datacol.io." && exit 1
fi

version=$(curl -s https://storage.googleapis.com/datacol-distros/binaries/latest.txt)
name="$PLATFORM.zip"
url="https://storage.googleapis.com/datacol-distros/binaries/$version/$name"

echo "==================================="
echo "Downloading DATACOL CLI version: $version"

tmp_path=$(mktemp -d)
response=$(curl --write-out %{http_code} --silent --output /dev/null $url)

if [[ "$response" != '200' ]]; then
echo "Got $response with $url" && exit 1
fi

bin_path=$tmp_path/$name
curl -Ls $url > $bin_path && unzip -q $bin_path -d $tmp_path
chmod +x $tmp_path/datacol && mv $tmp_path/datacol /usr/local/bin

echo '
Datacol installed successfully!
Run with: datacol
'

0 comments on commit 8edbad4

Please sign in to comment.