Add loading progress / revamped UX for logging (#983)

Adds a loading progress when deploying containers (in particular,
pushing..)

Revamps the logging so it's more "modern" and cleaner.
This commit is contained in:
Charlie Drage
2018-11-30 10:35:08 -05:00
committed by GitHub
parent e391473f5d
commit 5622eb92ba
35 changed files with 670 additions and 222 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/golang/glog"
imagev1 "github.com/openshift/api/image/v1"
"github.com/pkg/errors"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/occlient"
)
@@ -51,6 +52,9 @@ func Search(client *occlient.Client, name string) ([]string, error) {
// Exists returns true if the given component type is valid, false if not
func Exists(client *occlient.Client, componentType string) (bool, error) {
s := log.Spinner("Checking component")
defer s.End(false)
catalogList, err := List(client)
if err != nil {
return false, errors.Wrapf(err, "unable to list catalog")
@@ -58,6 +62,7 @@ func Exists(client *occlient.Client, componentType string) (bool, error) {
for _, supported := range catalogList {
if componentType == supported.Name || componentType == fmt.Sprintf("%s/%s", supported.Namespace, supported.Name) {
s.End(true)
return true, nil
}
}
@@ -67,6 +72,10 @@ func Exists(client *occlient.Client, componentType string) (bool, error) {
// VersionExists checks if that version exists, returns true if the given version exists, false if not
func VersionExists(client *occlient.Client, componentType string, componentVersion string) (bool, error) {
// Loading status
s := log.Spinner("Checking component version")
defer s.End(false)
// Retrieve the catalogList
catalogList, err := List(client)
if err != nil {
@@ -79,6 +88,7 @@ func VersionExists(client *occlient.Client, componentType string, componentVersi
// Now check to see if that version matches that components tag
for _, tag := range supported.Tags {
if componentVersion == tag {
s.End(true)
return true, nil
}
}
@@ -92,6 +102,7 @@ func VersionExists(client *occlient.Client, componentType string, componentVersi
// getDefaultBuilderImages returns the default builder images available in the
// openshift and the current namespaces
func getDefaultBuilderImages(client *occlient.Client) ([]CatalogImage, error) {
var imageStreams []imagev1.ImageStream
currentNamespace := client.GetCurrentProjectName()
@@ -158,6 +169,7 @@ func getDefaultBuilderImages(client *occlient.Client) ([]CatalogImage, error) {
}
}
glog.V(4).Infof("Found builder images: %v", builderImages)
return builderImages, nil
}

View File

@@ -2,6 +2,7 @@ package component
import (
"bufio"
"bytes"
"fmt"
"io"
"os"
@@ -15,6 +16,7 @@ import (
applabels "github.com/redhat-developer/odo/pkg/application/labels"
componentlabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/config"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/occlient"
"github.com/redhat-developer/odo/pkg/storage"
urlpkg "github.com/redhat-developer/odo/pkg/url"
@@ -140,6 +142,10 @@ func CreateFromGit(client *occlient.Client, params occlient.CreateArgs) error {
labels := componentlabels.GetLabels(params.Name, params.ApplicationName, true)
// Loading spinner
s := log.Spinnerf("Creating component %s", params.Name)
defer s.End(false)
// Parse componentImageType before adding to labels
_, imageName, imageTag, _, err := occlient.ParseImageName(params.ImageName)
if err != nil {
@@ -171,6 +177,8 @@ func CreateFromGit(client *occlient.Client, params occlient.CreateArgs) error {
if err != nil {
return errors.Wrapf(err, "unable to create git component %s", namespacedOpenShiftObject)
}
s.End(true)
return nil
}
@@ -199,6 +207,10 @@ func GetComponentPorts(client *occlient.Client, componentName string, applicatio
func CreateFromPath(client *occlient.Client, params occlient.CreateArgs) error {
labels := componentlabels.GetLabels(params.Name, params.ApplicationName, true)
// Loading spinner
s := log.Spinnerf("Creating component %s", params.Name)
defer s.End(false)
// Parse componentImageType before adding to labels
_, imageName, imageTag, _, err := occlient.ParseImageName(params.ImageName)
if err != nil {
@@ -233,12 +245,17 @@ func CreateFromPath(client *occlient.Client, params occlient.CreateArgs) error {
return err
}
s.End(true)
return nil
}
// Delete whole component
func Delete(client *occlient.Client, componentName string, applicationName string) error {
// Loading spinner
s := log.Spinnerf("Deleting component %s", componentName)
defer s.End(false)
cfg, err := config.New()
if err != nil {
return errors.Wrapf(err, "unable to create new configuration to delete %s", componentName)
@@ -284,6 +301,8 @@ func Delete(client *occlient.Client, componentName string, applicationName strin
}
}
s.End(true)
return nil
}
@@ -354,15 +373,21 @@ func PushLocal(client *occlient.Client, componentName string, applicationName st
targetPath := fmt.Sprintf("%s/src", s2iSrcPath)
// Copy the files to the pod
glog.V(4).Infof("Copying to pod %s", pod.Name)
s := log.Spinner("Copying files to pod")
err = client.CopyFile(path, pod.Name, targetPath, files)
if err != nil {
s.End(false)
return errors.Wrap(err, "unable push files to pod")
}
fmt.Fprintf(out, "Please wait, building component....\n")
s.End(true)
s = log.Spinner("Building component")
defer s.End(false)
// use pipes to write output from ExecCMDInContainer in yellow to 'out' io.Writer
pipeReader, pipeWriter := io.Pipe()
var cmdOutput string
go func() {
yellowFprintln := color.New(color.FgYellow).FprintlnFunc()
scanner := bufio.NewScanner(pipeReader)
@@ -370,7 +395,12 @@ func PushLocal(client *occlient.Client, componentName string, applicationName st
line := scanner.Text()
// color.Output is temporarily used as there is a error when passing in color.Output from cmd/create.go and casting to io.writer in windows
// TODO: Fix this in the future, more upstream in the code at cmd/create.go rather than within this function.
yellowFprintln(color.Output, line)
// If we are in debug mode, we should show the output
if log.IsDebug() {
yellowFprintln(color.Output, line)
}
cmdOutput += fmt.Sprintln(line)
}
}()
@@ -378,18 +408,26 @@ func PushLocal(client *occlient.Client, componentName string, applicationName st
// We will use the assemble-and-restart script located within the supervisord container we've created
[]string{"/var/lib/supervisord/bin/assemble-and-restart"},
pipeWriter, pipeWriter, nil, false)
if err != nil {
// If we fail, log the output
log.Errorf("Unable to build files\n%v", cmdOutput)
return errors.Wrap(err, "unable to execute assemble script")
}
s.End(true)
return nil
}
// Build component from BuildConfig.
// If 'streamLogs' is true than it streams build logs on stdout, set 'wait' to true if you want to return error if build fails.
// If 'wait' is true than it waits for build to successfully complete.
// If 'wait' is false than this function won't return error even if build failed.
func Build(client *occlient.Client, componentName string, applicationName string, streamLogs bool, wait bool, stdout io.Writer) error {
func Build(client *occlient.Client, componentName string, applicationName string, wait bool, stdout io.Writer) error {
// Loading spinner
s := log.Spinnerf("Triggering build from git")
defer s.End(false)
// Namespace the component
namespacedOpenShiftObject, err := util.NamespaceOpenShiftObject(componentName, applicationName)
@@ -401,17 +439,25 @@ func Build(client *occlient.Client, componentName string, applicationName string
if err != nil {
return errors.Wrapf(err, "unable to rebuild %s", componentName)
}
if streamLogs {
if err := client.FollowBuildLog(buildName, stdout); err != nil {
return errors.Wrapf(err, "unable to follow logs for %s", buildName)
}
// Retrieve the Build Log and write to buffer if debug is disabled, else we we output to stdout / debug.
var b bytes.Buffer
if !log.IsDebug() {
stdout = bufio.NewWriter(&b)
}
if err := client.FollowBuildLog(buildName, stdout); err != nil {
return errors.Wrapf(err, "unable to follow logs for %s", buildName)
}
if wait {
if err := client.WaitForBuildToFinish(buildName); err != nil {
return errors.Wrapf(err, "unable to wait for build %s", buildName)
return errors.Wrapf(err, "unable to build %s, error: %s", buildName, b.String())
}
}
s.End(true)
return nil
}
@@ -574,7 +620,7 @@ func Update(client *occlient.Client, componentName string, applicationName strin
}
// Finally, we build!
err = Build(client, componentName, applicationName, true, true, stdout)
err = Build(client, componentName, applicationName, true, stdout)
if err != nil {
return errors.Wrapf(err, "unable to build the component %v", componentName)
}
@@ -618,7 +664,7 @@ func Update(client *occlient.Client, componentName string, applicationName strin
}
// Build it
err = Build(client, componentName, applicationName, true, true, stdout)
err = Build(client, componentName, applicationName, true, stdout)
} else if newSourceType == "local" || newSourceType == "binary" {

113
pkg/log/fidget/spinner.go Normal file
View File

@@ -0,0 +1,113 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
This package is a FORK of https://github.com/kubernetes-sigs/kind/blob/master/pkg/log/status.go
See above license
*/
// Package fidget implements CLI functionality for bored users waiting for results
package fidget
import (
"fmt"
"io"
"sync"
"time"
)
// custom CLI loading spinner for kind
var spinnerFrames = []string{
"⠈⠁",
"⠈⠑",
"⠈⠱",
"⠈⡱",
"⢀⡱",
"⢄⡱",
"⢄⡱",
"⢆⡱",
"⢎⡱",
"⢎⡰",
"⢎⡠",
"⢎⡀",
"⢎⠁",
"⠎⠁",
"⠊⠁",
}
// Spinner is a simple and efficient CLI loading spinner used by kind
// It is simplistic and assumes that the line length will not change.
// It is best used indirectly via log.Status (see parent package)
type Spinner struct {
frames []string
stop chan struct{}
ticker *time.Ticker
writer io.Writer
mu *sync.Mutex
// protected by mu
prefix string
suffix string
}
// NewSpinner initializes and returns a new Spinner that will write to
func NewSpinner(w io.Writer) *Spinner {
return &Spinner{
frames: spinnerFrames,
stop: make(chan struct{}, 1),
ticker: time.NewTicker(time.Millisecond * 100),
mu: &sync.Mutex{},
writer: w,
}
}
// SetPrefix sets the prefix to print before the spinner
func (s *Spinner) SetPrefix(prefix string) {
s.mu.Lock()
s.prefix = prefix
s.mu.Unlock()
}
// SetSuffix sets the suffix to print after the spinner
func (s *Spinner) SetSuffix(suffix string) {
s.mu.Lock()
s.suffix = suffix
s.mu.Unlock()
}
// Start starts the spinner running
func (s *Spinner) Start() {
go func() {
for {
for _, frame := range s.frames {
select {
case <-s.stop:
return
case <-s.ticker.C:
func() {
s.mu.Lock()
defer s.mu.Unlock()
fmt.Fprintf(s.writer, "\r%s%s%s", s.prefix, frame, s.suffix)
}()
}
}
}
}()
}
// Stop signals the spinner to stop
func (s *Spinner) Stop() {
s.stop <- struct{}{}
}

222
pkg/log/status.go Normal file
View File

@@ -0,0 +1,222 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
This package is a FORK of https://github.com/kubernetes-sigs/kind/blob/master/pkg/log/status.go
See above license
*/
// Package log contains logging related functionality
package log
import (
"fmt"
"io"
"os"
"strings"
"github.com/fatih/color"
"github.com/redhat-developer/odo/pkg/log/fidget"
"github.com/spf13/pflag"
"golang.org/x/crypto/ssh/terminal"
)
// Spacing for logging
const suffixSpacing = " "
// Status is used to track ongoing status in a CLI, with a nice loading spinner
// when attached to a terminal
type Status struct {
spinner *fidget.Spinner
status string
writer io.Writer
}
// NewStatus creates a new default Status
func NewStatus(w io.Writer) *Status {
spin := fidget.NewSpinner(w)
s := &Status{
spinner: spin,
writer: w,
}
return s
}
// StatusFriendlyWriter is used to wrap another Writer to make it toggle the
// status spinner before and after writes so that they do not collide
type StatusFriendlyWriter struct {
status *Status
inner io.Writer
}
var _ io.Writer = &StatusFriendlyWriter{}
func (ww *StatusFriendlyWriter) Write(p []byte) (n int, err error) {
ww.status.spinner.Stop()
_, err = ww.inner.Write([]byte("\r"))
if err != nil {
return n, err
}
n, err = ww.inner.Write(p)
ww.status.spinner.Start()
return n, err
}
// WrapWriter returns a StatusFriendlyWriter for w
func (s *Status) WrapWriter(w io.Writer) io.Writer {
return &StatusFriendlyWriter{
status: s,
inner: w,
}
}
// MaybeWrapWriter returns a StatusFriendlyWriter for w IFF w and spinner's
// output are a terminal, otherwise it returns w
func (s *Status) MaybeWrapWriter(w io.Writer) io.Writer {
if IsTerminal(s.writer) && IsTerminal(w) {
return s.WrapWriter(w)
}
return w
}
// IsTerminal returns true if the writer w is a terminal
func IsTerminal(w io.Writer) bool {
if v, ok := (w).(*os.File); ok {
return terminal.IsTerminal(int(v.Fd()))
}
return false
}
// Start starts a new phase of the status, if attached to a terminal
// there will be a loading spinner with this status
func (s *Status) Start(status string, debug bool) {
s.End(true)
// set new status
isTerm := IsTerminal(s.writer)
s.status = status
// If we are in debug mode, don't spin!
if !isTerm || debug {
fmt.Fprintf(s.writer, " • %s ...\n", s.status)
} else {
s.spinner.SetSuffix(fmt.Sprintf(" %s", s.status))
s.spinner.Start()
}
}
// End completes the current status, ending any previous spinning and
// marking the status as success or failure
func (s *Status) End(success bool) {
if s.status == "" {
return
}
isTerm := IsTerminal(s.writer)
if isTerm {
s.spinner.Stop()
fmt.Fprint(s.writer, "\r")
}
if success {
green := color.New(color.FgGreen).SprintFunc()
fmt.Fprintf(s.writer, " %s %s\n", green("✓"), s.status)
} else {
red := color.New(color.FgRed).SprintFunc()
fmt.Fprintf(s.writer, " %s %s\n", red("✗"), s.status)
}
s.status = ""
}
// Namef will output the name of the component / application / project in a *bolded* manner
func Namef(format string, a ...interface{}) {
bold := color.New(color.Bold).SprintFunc()
fmt.Printf("%s\n", bold(fmt.Sprintf(format, a...)))
}
// Progressf will output in an appropriate "progress" manner
func Progressf(format string, a ...interface{}) {
fmt.Printf(" %s\n", fmt.Sprintf(format, a...))
}
// Successf will output in an appropriate "progress" manner
func Successf(format string, a ...interface{}) {
green := color.New(color.FgGreen).SprintFunc()
fmt.Printf(" %s%s%s\n", green("OK "), suffixSpacing, fmt.Sprintf(format, a...))
}
// Errorf will output in an appropriate "progress" manner
func Errorf(format string, a ...interface{}) {
red := color.New(color.FgRed).SprintFunc()
fmt.Printf(" %s%s%s\n", red("ERR"), suffixSpacing, fmt.Sprintf(format, a...))
}
// Error will output in an appropriate "progress" manner
func Error(a ...interface{}) {
red := color.New(color.FgRed).SprintFunc()
fmt.Printf(" %s%s%s\n", red("ERR"), suffixSpacing, fmt.Sprintln(a...))
}
// Info will simply print out information on a new (bolded) line
// this is intended as information *after* something has been deployed
func Info(a ...interface{}) {
bold := color.New(color.Bold).SprintFunc()
fmt.Printf("%s\n", bold(fmt.Sprintln(a...)))
}
// Infof will simply print out information on a new (bolded) line
// this is intended as information *after* something has been deployed
func Infof(format string, a ...interface{}) {
bold := color.New(color.Bold).SprintFunc()
fmt.Printf("%s\n", bold(fmt.Sprintf(format, a...)))
}
// Askf will print out information, but in an "Ask" way (without newline)
func Askf(format string, a ...interface{}) {
bold := color.New(color.Bold).SprintFunc()
fmt.Printf("%s", bold(fmt.Sprintf(format, a...)))
}
// Status creates a spinner, sets the prefix then returns it.
// Remember to use .End(bool) to stop the spin / when you're done.
// For example: defer s.End(false)
func Spinner(status string) *Status {
s := NewStatus(os.Stdout)
s.Start(status, IsDebug())
return s
}
// Statusf creates a spinner, sets the prefix then returns it.
// Remember to use .End(bool) to stop the spin / when you're done.
// For example: defer s.End(false)
func Spinnerf(format string, a ...interface{}) *Status {
s := NewStatus(os.Stdout)
s.Start(fmt.Sprintf(format, a...), IsDebug())
return s
}
// IsDebug returns true if we are debugging (-v is set to anything but 0)
func IsDebug() bool {
flag := pflag.Lookup("v")
if flag != nil {
return !strings.Contains(pflag.Lookup("v").Value.String(), "0")
}
return false
}

View File

@@ -24,6 +24,7 @@ import (
dockerapiv10 "github.com/openshift/api/image/docker10"
"github.com/pkg/errors"
"github.com/redhat-developer/odo/pkg/config"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/util"
servicecatalogclienset "github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset/typed/servicecatalog/v1beta1"
@@ -389,11 +390,13 @@ func isServerUp(server string) bool {
ocRequestTimeout = time.Duration(cfg.GetTimeout()) * time.Second
}
glog.V(4).Infof("Trying to connect to server %v", u.Host)
_, connectionError := net.DialTimeout("tcp", u.Host, time.Duration(ocRequestTimeout))
if connectionError != nil {
glog.V(4).Info(errors.Wrap(connectionError, "unable to connect to server"))
return false
}
glog.V(4).Infof("Server %v is up", server)
return true
}
@@ -1531,6 +1534,8 @@ func (c *Client) WaitAndGetDC(name string, field string, value string, timeout t
// WaitAndGetPod block and waits until pod matching selector is in in Running state
func (c *Client) WaitAndGetPod(selector string) (*corev1.Pod, error) {
glog.V(4).Infof("Waiting for %s pod", selector)
s := log.Spinner("Waiting for pod to start")
defer s.End(false)
w, err := c.kubeClient.CoreV1().Pods(c.Namespace).Watch(metav1.ListOptions{
LabelSelector: selector,
@@ -1555,6 +1560,7 @@ func (c *Client) WaitAndGetPod(selector string) (*corev1.Pod, error) {
glog.V(4).Infof("Status of %s pod is %s", e.Name, e.Status.Phase)
switch e.Status.Phase {
case corev1.PodRunning:
s.End(true)
glog.V(4).Infof("Pod %s is running.", e.Name)
podChannel <- e
break loop
@@ -1625,10 +1631,6 @@ func (c *Client) FollowBuildLog(buildName string, stdout io.Writer) error {
}
defer rd.Close()
// Set the colour of the stdout output..
color.Set(color.FgYellow)
defer color.Unset()
if _, err = io.Copy(stdout, rd); err != nil {
return errors.Wrapf(err, "error streaming logs for %s", buildName)
}

View File

@@ -6,9 +6,11 @@ import (
"strings"
"github.com/pkg/errors"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/occlient"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/odo/util/completion"
@@ -78,26 +80,26 @@ If no app name is passed, a default app name will be auto-generated.
// Desired app name is not passed so, generate a new app name
// Fetch existing list of apps
apps, err := application.List(client)
util.CheckError(err, "")
odoutil.CheckError(err, "")
// Generate a random name that's not already in use for the existing apps
appName, err = application.GetDefaultAppName(apps)
util.CheckError(err, "")
odoutil.CheckError(err, "")
}
// validate application name
err := util.ValidateName(appName)
util.CheckError(err, "")
fmt.Printf("Creating application: %v in project: %v\n", appName, projectName)
err := odoutil.ValidateName(appName)
odoutil.CheckError(err, "")
log.Progressf("Creating application: %v in project: %v", appName, projectName)
err = application.Create(client, appName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
err = application.SetCurrent(client, appName)
// TODO: updating the app name should be done via SetCurrent and passing the Context
// not strictly needed here but Context should stay in sync
context.Application = appName
util.CheckError(err, "")
fmt.Printf("Switched to application: %v in project: %v\n", appName, projectName)
odoutil.CheckError(err, "")
log.Infof("Switched to application: %v in project: %v", appName, projectName)
},
}
@@ -118,10 +120,10 @@ var applicationGetCmd = &cobra.Command{
return
}
if app == "" {
fmt.Printf("There's no active application.\nYou can create one by running 'odo application create <name>'.\n")
log.Infof("There's no active application.\nYou can create one by running 'odo application create <name>'.")
return
}
fmt.Printf("The current application is: %v in project: %v\n", app, projectName)
log.Infof("The current application is: %v in project: %v", app, projectName)
},
}
@@ -147,27 +149,27 @@ var applicationDeleteCmd = &cobra.Command{
// Print App Information which will be deleted
err := printDeleteAppInfo(client, appName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
exists, err := application.Exists(client, appName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
if !exists {
fmt.Printf("Application %v in project %v does not exist\n", appName, projectName)
log.Errorf("Application %v in project %v does not exist", appName, projectName)
os.Exit(1)
}
if applicationForceDeleteFlag {
confirmDeletion = "y"
} else {
fmt.Printf("Are you sure you want to delete the application: %v from project: %v? [y/N] ", appName, projectName)
log.Askf("Are you sure you want to delete the application: %v from project: %v? [y/N]: ", appName, projectName)
fmt.Scanln(&confirmDeletion)
}
if strings.ToLower(confirmDeletion) == "y" {
err := application.Delete(client, appName)
util.CheckError(err, "")
fmt.Printf("Deleted application: %s from project: %v\n", appName, projectName)
odoutil.CheckError(err, "")
log.Infof("Deleted application: %s from project: %v", appName, projectName)
} else {
fmt.Printf("Aborting deletion of application: %v\n", appName)
log.Infof("Aborting deletion of application: %v", appName)
}
},
}
@@ -189,9 +191,9 @@ var applicationListCmd = &cobra.Command{
projectName := context.Project
apps, err := application.ListInProject(client)
util.CheckError(err, "unable to get list of applications")
odoutil.CheckError(err, "unable to get list of applications")
if len(apps) > 0 {
fmt.Printf("The project '%v' has the following applications:\n", projectName)
log.Infof("The project '%v' has the following applications:", projectName)
tabWriter := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(tabWriter, "ACTIVE", "\t", "NAME")
for _, app := range apps {
@@ -203,7 +205,7 @@ var applicationListCmd = &cobra.Command{
}
tabWriter.Flush()
} else {
fmt.Printf("There are no applications deployed in the project '%v'.\n", projectName)
log.Infof("There are no applications deployed in the project '%v'.", projectName)
}
},
}
@@ -217,10 +219,12 @@ var applicationSetCmd = &cobra.Command{
`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("Please provide application name")
log.Error("Please provide application name")
os.Exit(1)
}
if len(args) > 1 {
return fmt.Errorf("Only one argument (application name) is allowed")
log.Error("Only one argument (application name) is allowed")
os.Exit(1)
}
return nil
}, Run: func(cmd *cobra.Command, args []string) {
@@ -231,15 +235,15 @@ var applicationSetCmd = &cobra.Command{
// error if application does not exist
appName := args[0]
exists, err := application.Exists(client, appName)
util.CheckError(err, "unable to check if application exists")
odoutil.CheckError(err, "unable to check if application exists")
if !exists {
fmt.Printf("Application %v does not exist\n", appName)
log.Errorf("Application %v does not exist", appName)
os.Exit(1)
}
err = application.SetCurrent(client, appName)
util.CheckError(err, "")
fmt.Printf("Switched to application: %v in project: %v\n", args[0], projectName)
odoutil.CheckError(err, "")
log.Infof("Switched to application: %v in project: %v", args[0], projectName)
// TODO: updating the app name should be done via SetCurrent and passing the Context
// not strictly needed here but Context should stay in sync
@@ -263,32 +267,32 @@ var applicationDescribeCmd = &cobra.Command{
appName := context.Application
if len(args) == 0 {
if appName == "" {
fmt.Printf("There's no active application in project: %v\n", projectName)
log.Errorf("There's no active application in project: %v", projectName)
os.Exit(1)
}
} else {
appName = args[0]
//Check whether application exist or not
exists, err := application.Exists(client, appName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
if !exists {
fmt.Printf("Application with the name %s does not exist in %s \n", appName, projectName)
log.Errorf("Application with the name %s does not exist in %s ", appName, projectName)
os.Exit(1)
}
}
// List of Component
componentList, err := component.List(client, appName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
if len(componentList) == 0 {
fmt.Printf("Application %s has no components deployed.\n", appName)
log.Errorf("Application %s has no components deployed.", appName)
os.Exit(1)
}
fmt.Printf("Application Name: %s has %v components:\n--------------------------------------\n", appName, len(componentList))
for _, currentComponent := range componentList {
componentDesc, err := component.GetComponentDesc(client, currentComponent.Name, appName)
util.CheckError(err, "")
util.PrintComponentInfo(currentComponent.Name, componentDesc)
odoutil.CheckError(err, "")
odoutil.PrintComponentInfo(currentComponent.Name, componentDesc)
fmt.Println("--------------------------------------")
}
@@ -320,7 +324,7 @@ func NewCmdApplication() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
applicationCmd.Annotations = map[string]string{"command": "other"}
applicationCmd.SetUsageTemplate(util.CmdUsageTemplate)
applicationCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
completion.RegisterCommandHandler(applicationDescribeCmd, completion.AppCompletionHandler)
completion.RegisterCommandHandler(applicationDeleteCmd, completion.AppCompletionHandler)

View File

@@ -2,13 +2,15 @@ package catalog
import (
"fmt"
"github.com/olekukonko/tablewriter"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
"os"
"strings"
"text/tabwriter"
"github.com/olekukonko/tablewriter"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/catalog"
svc "github.com/redhat-developer/odo/pkg/service"
"github.com/spf13/cobra"
@@ -49,10 +51,11 @@ var catalogListComponentCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
client := genericclioptions.Client(cmd)
catalogList, err := catalog.List(client)
util.CheckError(err, "unable to list components")
odoutil.CheckError(err, "unable to list components")
switch len(catalogList) {
case 0:
fmt.Printf("No deployable components found\n")
log.Errorf("No deployable components found")
os.Exit(1)
default:
currentProject := client.GetCurrentProjectName()
w := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
@@ -93,10 +96,11 @@ var catalogListServiceCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
client := genericclioptions.Client(cmd)
catalogList, err := svc.ListCatalog(client)
util.CheckError(err, "unable to list services because Service Catalog is not enabled in your cluster")
odoutil.CheckError(err, "unable to list services because Service Catalog is not enabled in your cluster")
switch len(catalogList) {
case 0:
fmt.Printf("No deployable services found\n")
log.Errorf("No deployable services found")
os.Exit(1)
default:
w := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, "NAME", "\t", "PLANS")
@@ -141,13 +145,14 @@ components.
client := genericclioptions.Client(cmd)
searchTerm := args[0]
components, err := catalog.Search(client, searchTerm)
util.CheckError(err, "unable to search for components")
odoutil.CheckError(err, "unable to search for components")
switch len(components) {
case 0:
fmt.Printf("No component matched the query: %v\n", searchTerm)
log.Errorf("No component matched the query: %v", searchTerm)
os.Exit(1)
default:
fmt.Println("The following components were found:")
log.Infof("The following components were found:")
for _, component := range components {
fmt.Printf("- %v\n", component)
}
@@ -171,11 +176,12 @@ services from service catalog.
client := genericclioptions.Client(cmd)
searchTerm := args[0]
components, err := svc.Search(client, searchTerm)
util.CheckError(err, "unable to search for services")
odoutil.CheckError(err, "unable to search for services")
switch len(components) {
case 0:
fmt.Printf("No service matched the query: %v\n", searchTerm)
log.Errorf("No service matched the query: %v", searchTerm)
os.Exit(1)
default:
w := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, "NAME", "\t", "PLANS")
@@ -213,7 +219,7 @@ This describes the service and the associated plans.
client := genericclioptions.Client(cmd)
serviceName := args[0]
service, plans, err := svc.GetServiceClassAndPlans(client, serviceName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
table := tablewriter.NewWriter(os.Stdout)
table.SetBorder(false)
@@ -281,7 +287,8 @@ This describes the service and the associated plans.
}
table.Render()
} else {
fmt.Printf("No plans found for service %s\n", serviceName)
log.Errorf("No plans found for service %s", serviceName)
os.Exit(1)
}
},
}
@@ -298,7 +305,7 @@ func NewCmdCatalog() *cobra.Command {
catalogDescribeCmd.AddCommand(catalogDescribeServiceCmd)
// Add a defined annotation in order to appear in the help menu
catalogCmd.Annotations = map[string]string{"command": "other"}
catalogCmd.SetUsageTemplate(util.CmdUsageTemplate)
catalogCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
return catalogCmd
}

View File

@@ -2,12 +2,14 @@ package component
import (
"fmt"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/odo/util/completion"
"github.com/golang/glog"
"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/spf13/cobra"
)
@@ -48,10 +50,10 @@ var componentGetCmd = &cobra.Command{
fmt.Print(component)
} else {
if component == "" {
fmt.Printf("No component is set as current\n")
log.Info("No component is set as current")
return
}
fmt.Printf("The current component is: %v\n", component)
log.Infof("The current component is: %v", component)
}
},
}
@@ -71,7 +73,7 @@ var componentSetCmd = &cobra.Command{
componentName := context.Component(args[0])
err := component.SetCurrent(componentName, applicationName, projectName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
fmt.Printf("Switched to component: %v\n", componentName)
},
}
@@ -96,7 +98,7 @@ func NewCmdComponent() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
componentCmd.Annotations = map[string]string{"command": "component"}
componentCmd.SetUsageTemplate(util.CmdUsageTemplate)
componentCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
return componentCmd
}

View File

@@ -5,6 +5,7 @@ import (
"os"
"strings"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/odo/util/completion"
@@ -119,7 +120,7 @@ A full list of component types that can be deployed is available using: 'odo cat
}
if checkFlag > 1 {
fmt.Println("The source can be either --binary or --local or --git")
log.Error("The source can be either --binary or --local or --git")
os.Exit(1)
}
@@ -142,7 +143,8 @@ A full list of component types that can be deployed is available using: 'odo cat
exists, err := catalog.Exists(client, componentType)
odoutil.CheckError(err, "")
if !exists {
fmt.Printf("Invalid component type: %v\nRun 'odo catalog list components' to see a list of supported component types\n", componentType)
log.Errorf("Invalid component type: %v", componentType)
log.Info("Run 'odo catalog list components' for a list of supported component types")
os.Exit(1)
}
@@ -150,7 +152,8 @@ A full list of component types that can be deployed is available using: 'odo cat
versionExists, err := catalog.VersionExists(client, componentType, componentVersion)
odoutil.CheckError(err, "")
if !versionExists {
fmt.Printf("Invalid component version: %v\nRun 'odo catalog list components' to see a list of supported component type versions\n", componentVersion)
log.Errorf("Invalid component version: %v", componentVersion)
log.Info("Run 'odo catalog list components' to see a list of supported component type versions")
os.Exit(1)
}
@@ -165,7 +168,7 @@ A full list of component types that can be deployed is available using: 'odo cat
exists, err = component.Exists(client, componentName, applicationName)
odoutil.CheckError(err, "")
if exists {
fmt.Printf("component with the name %s already exists in the current application\n", componentName)
log.Errorf("component with the name %s already exists in the current application", componentName)
os.Exit(1)
}
@@ -201,17 +204,16 @@ A full list of component types that can be deployed is available using: 'odo cat
},
)
odoutil.CheckError(err, "")
fmt.Printf("Triggering build from %s.\n\n", componentGit)
// Git is the only one using BuildConfig since we need to retrieve the git
err = component.Build(client, componentName, applicationName, true, true, stdout)
err = component.Build(client, componentName, applicationName, true, stdout)
odoutil.CheckError(err, "")
} else if len(componentLocal) != 0 {
fileInfo, err := os.Stat(componentPath)
odoutil.CheckError(err, "")
if !fileInfo.IsDir() {
fmt.Println("Please provide a path to the directory")
log.Errorf("Please provide a path to the directory")
os.Exit(1)
}
@@ -274,23 +276,23 @@ A full list of component types that can be deployed is available using: 'odo cat
ports, err := component.GetComponentPorts(client, componentName, applicationName)
odoutil.CheckError(err, "")
fmt.Printf("Component '%s' was created", componentName)
if len(ports) > 1 {
fmt.Printf(" and ports %s were opened\n", strings.Join(ports, ","))
log.Successf("Component '%s' was created and ports %s were opened", componentName, strings.Join(ports, ","))
} else if len(ports) == 1 {
fmt.Printf(" and port %s was opened\n", ports[0])
log.Successf("Component '%s' was created and port %s was opened", componentName, ports[0])
}
if len(componentGit) == 0 {
fmt.Printf("To push source code to the component run 'odo push'\n")
}
// after component is successfully created, set is as active
err = application.SetCurrent(client, applicationName)
odoutil.CheckError(err, "")
err = component.SetCurrent(componentName, applicationName, projectName)
odoutil.CheckError(err, "")
fmt.Printf("\nComponent '%s' is now set as active component.\n", componentName)
log.Successf("Component '%s' is now set as active component", componentName)
if len(componentGit) == 0 {
log.Info("To push source code to the component run 'odo push'")
}
},
}

View File

@@ -2,10 +2,12 @@ package component
import (
"fmt"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
"strings"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/golang/glog"
"github.com/redhat-developer/odo/pkg/component"
"github.com/spf13/cobra"
@@ -43,26 +45,26 @@ var componentDeleteCmd = &cobra.Command{
if componentForceDeleteFlag {
confirmDeletion = "y"
} else {
fmt.Printf("Are you sure you want to delete %v from %v? [y/N] ", componentName, applicationName)
log.Askf("Are you sure you want to delete %v from %v? [y/N]: ", componentName, applicationName)
fmt.Scanln(&confirmDeletion)
}
if strings.ToLower(confirmDeletion) == "y" {
err := component.Delete(client, componentName, applicationName)
util.CheckError(err, "")
fmt.Printf("Component %s from application %s has been deleted\n", componentName, applicationName)
odoutil.CheckError(err, "")
log.Successf("Component %s from application %s has been deleted", componentName, applicationName)
currentComponent, err := component.GetCurrent(applicationName, projectName)
util.CheckError(err, "Unable to get current component")
odoutil.CheckError(err, "Unable to get current component")
if currentComponent == "" {
fmt.Println("No default component has been set")
log.Info("No default component has been set")
} else {
fmt.Printf("Default component set to: %s\n", currentComponent)
log.Infof("Default component set to: %s", currentComponent)
}
} else {
fmt.Printf("Aborting deletion of component: %v\n", componentName)
log.Infof("Aborting deletion of component: %v", componentName)
}
},
}
@@ -73,7 +75,7 @@ func NewCmdDelete() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
componentDeleteCmd.Annotations = map[string]string{"command": "component"}
componentDeleteCmd.SetUsageTemplate(util.CmdUsageTemplate)
componentDeleteCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
//Adding `--project` flag
addProjectFlag(componentDeleteCmd)

View File

@@ -3,7 +3,7 @@ package component
import (
"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/spf13/cobra"
)
@@ -29,9 +29,9 @@ var describeCmd = &cobra.Command{
componentName = context.Component(args[0])
}
componentDesc, err := component.GetComponentDesc(client, componentName, applicationName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
util.PrintComponentInfo(componentName, componentDesc)
odoutil.PrintComponentInfo(componentName, componentDesc)
},
}
@@ -39,7 +39,7 @@ var describeCmd = &cobra.Command{
func NewCmdDescribe() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
describeCmd.Annotations = map[string]string{"command": "component"}
describeCmd.SetUsageTemplate(util.CmdUsageTemplate)
describeCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
//Adding `--project` flag
addProjectFlag(describeCmd)

View File

@@ -1,13 +1,14 @@
package component
import (
"fmt"
"os"
"github.com/golang/glog"
"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/secret"
"os"
svc "github.com/redhat-developer/odo/pkg/service"
"github.com/spf13/cobra"
@@ -77,10 +78,10 @@ DB_PASSWORD=secret
suppliedName := args[0]
svcSxists, err := svc.SvcExists(client, suppliedName, applicationName)
util.CheckError(err, "Unable to determine if service %s exists", suppliedName)
odoutil.CheckError(err, "Unable to determine if service %s exists", suppliedName)
cmpExists, err := component.Exists(client, suppliedName, applicationName)
util.CheckError(err, "Unable to determine if component %s exists", suppliedName)
odoutil.CheckError(err, "Unable to determine if component %s exists", suppliedName)
if svcSxists {
if cmpExists {
@@ -93,8 +94,7 @@ DB_PASSWORD=secret
// which we can link to
_, err = client.GetServiceBinding(serviceName, projectName)
if err != nil {
fmt.Printf(`The service was not created via Odo.
Please delete the service and recreate it using 'odo service create %s'`, serviceName)
log.Errorf(`The service was not created via Odo. Please delete the service and recreate it using 'odo service create %s'`, serviceName)
os.Exit(1)
}
@@ -103,35 +103,33 @@ Please delete the service and recreate it using 'odo service create %s'`, servic
// this is done because the secret is only created after the Pod that runs the
// service is in running state.
// This can take a long time to occur if the image of the service has yet to be downloaded
fmt.Printf("Waiting for secret of service %s to come up\n", serviceName)
log.Progressf("Waiting for secret of service %s to come up", serviceName)
_, err = client.WaitAndGetSecret(serviceName, projectName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
} else {
// we also need to check whether there is a secret with the same name as the service
// the secret should have been created along with the secret
_, err = client.GetSecret(serviceName, projectName)
if err != nil {
fmt.Printf(`The service %s created by 'odo service create' is being provisioned.
You may have to wait a few seconds until OpenShift fully provisions it.`, serviceName)
log.Errorf(`The service %s created by 'odo service create' is being provisioned. You may have to wait a few seconds until OpenShift fully provisions it.`, serviceName)
os.Exit(1)
}
}
err = client.LinkSecret(serviceName, sourceComponentName, applicationName, projectName)
util.CheckError(err, "")
fmt.Printf("Service %s has been successfully linked to the component %s.\n", serviceName, sourceComponentName)
odoutil.CheckError(err, "")
log.Successf("Service %s has been successfully linked to the component %s", serviceName, sourceComponentName)
} else if cmpExists {
targetComponent := args[0]
secretName, err := secret.DetermineSecretName(client, targetComponent, applicationName, port)
util.CheckError(err, "")
odoutil.CheckError(err, "")
err = client.LinkSecret(secretName, sourceComponentName, applicationName, projectName)
util.CheckError(err, "")
fmt.Printf("Component %s has been successfully linked to component %s.\n", targetComponent, sourceComponentName)
odoutil.CheckError(err, "")
log.Successf("Component %s has been successfully linked to component %s", targetComponent, sourceComponentName)
} else {
fmt.Printf(`Neither a service nor a component named %s could be located
Please create one of the two before attempting to use odo link`, suppliedName)
log.Errorf(`Neither a service nor a component named %s could be located. Please create one of the two before attempting to use odo link`, suppliedName)
os.Exit(1)
}
},
@@ -144,7 +142,7 @@ func NewCmdLink() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
linkCmd.Annotations = map[string]string{"command": "component"}
linkCmd.SetUsageTemplate(util.CmdUsageTemplate)
linkCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
//Adding `--project` flag
addProjectFlag(linkCmd)
//Adding `--application` flag

View File

@@ -2,11 +2,12 @@ package component
import (
"fmt"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
"os"
"text/tabwriter"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/component"
"github.com/spf13/cobra"
)
@@ -25,7 +26,7 @@ var componentListCmd = &cobra.Command{
applicationName := context.Application
components, err := component.List(client, applicationName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
if len(components) == 0 {
fmt.Println("There are no components deployed.")
return

View File

@@ -1,10 +1,11 @@
package component
import (
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
"os"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/component"
"github.com/spf13/cobra"
)
@@ -38,7 +39,7 @@ var logCmd = &cobra.Command{
// Retrieve the log
err := component.GetLogs(client, componentName, applicationName, logFollow, stdout)
util.CheckError(err, "Unable to retrieve logs, does your component exist?")
odoutil.CheckError(err, "Unable to retrieve logs, does your component exist?")
},
}
@@ -48,7 +49,7 @@ func NewCmdLog() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
logCmd.Annotations = map[string]string{"command": "component"}
logCmd.SetUsageTemplate(util.CmdUsageTemplate)
logCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
//Adding `--project` flag
addProjectFlag(logCmd)

View File

@@ -6,6 +6,7 @@ import (
"os"
"runtime"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
@@ -46,7 +47,7 @@ var pushCmd = &cobra.Command{
}
componentName := context.Component(argComponent)
fmt.Printf("Pushing changes to component: %v\n", componentName)
log.Namef("Pushing changes to component: %v", componentName)
sourceType, sourcePath, err := component.GetComponentSource(client, componentName, applicationName)
odoutil.CheckError(err, "unable to get component source")
@@ -55,7 +56,7 @@ var pushCmd = &cobra.Command{
// use value of '--dir' as source if it was used
if len(componentLocal) != 0 {
if sourceType == "binary" {
fmt.Printf("Unable to push local directory:%s to component %s that uses binary %s.\n", componentLocal, componentName, sourcePath)
log.Errorf("Unable to push local directory:%s to component %s that uses binary %s.", componentLocal, componentName, sourcePath)
os.Exit(1)
}
sourcePath = util.GenFileURL(componentLocal, runtime.GOOS)
@@ -65,7 +66,7 @@ var pushCmd = &cobra.Command{
odoutil.CheckError(err, fmt.Sprintf("unable to parse source %s from component %s", sourcePath, componentName))
if u.Scheme != "" && u.Scheme != "file" {
fmt.Printf("Component %s has invalid source path %s", componentName, u.Scheme)
log.Errorf("Component %s has invalid source path %s", componentName, u.Scheme)
os.Exit(1)
}
@@ -84,20 +85,20 @@ var pushCmd = &cobra.Command{
glog.V(4).Infof("Copying file %s to pod", localLocation)
err = component.PushLocal(client, componentName, applicationName, dir, os.Stdout, []string{localLocation})
}
odoutil.CheckError(err, fmt.Sprintf("failed to push component: %v", componentName))
odoutil.CheckError(err, fmt.Sprintf("Failed to push component: %v", componentName))
case "git":
// currently we don't support changing build type
// it doesn't make sense to use --dir with git build
if len(componentLocal) != 0 {
fmt.Printf("Unable to push local directory:%s to component %s that uses Git repository:%s.\n", componentLocal, componentName, sourcePath)
log.Errorf("Unable to push local directory:%s to component %s that uses Git repository:%s.", componentLocal, componentName, sourcePath)
os.Exit(1)
}
err := component.Build(client, componentName, applicationName, true, true, stdout)
err := component.Build(client, componentName, applicationName, true, stdout)
odoutil.CheckError(err, fmt.Sprintf("failed to push component: %v", componentName))
}
fmt.Printf("changes successfully pushed to component: %v\n", componentName)
log.Successf("Changes successfully pushed to component: %v", componentName)
},
}

View File

@@ -1,7 +1,6 @@
package component
import (
"fmt"
"os"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
@@ -9,6 +8,10 @@ import (
"github.com/redhat-developer/odo/pkg/odo/util/completion"
pkgUtil "github.com/redhat-developer/odo/pkg/util"
"github.com/redhat-developer/odo/pkg/log"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/fatih/color"
"github.com/redhat-developer/odo/pkg/component"
"github.com/spf13/cobra"
@@ -54,7 +57,7 @@ var updateCmd = &cobra.Command{
}
if checkFlag != 1 {
fmt.Println("The source can be either --binary or --local or --git")
log.Errorf("The source can be either --binary or --local or --git")
os.Exit(1)
}
@@ -66,33 +69,33 @@ var updateCmd = &cobra.Command{
}
if len(applicationName) == 0 {
fmt.Println("Cannot update as no application is set as active")
log.Error("Cannot update as no application is set as active")
os.Exit(1)
}
if len(componentGit) != 0 {
err := component.Update(client, componentName, applicationName, "git", componentGit, stdout)
util.CheckError(err, "")
fmt.Printf("The component %s was updated successfully\n", componentName)
odoutil.CheckError(err, "")
log.Successf("The component %s was updated successfully", componentName)
} else if len(componentLocal) != 0 {
// we want to use and save absolute path for component
dir, err := pkgUtil.GetAbsPath(componentLocal)
util.CheckError(err, "")
fileInfo, err := os.Stat(dir)
util.CheckError(err, "")
odoutil.CheckError(err, "")
if !fileInfo.IsDir() {
fmt.Println("Please provide a path to the directory")
log.Error("Please provide a path to the directory")
os.Exit(1)
}
err = component.Update(client, componentName, applicationName, "local", dir, stdout)
util.CheckError(err, "")
fmt.Printf("The component %s was updated successfully, please use 'odo push' to push your local changes\n", componentName)
odoutil.CheckError(err, "")
log.Successf("The component %s was updated successfully, please use 'odo push' to push your local changes", componentName)
} else if len(componentBinary) != 0 {
path, err := pkgUtil.GetAbsPath(componentBinary)
util.CheckError(err, "")
err = component.Update(client, componentName, applicationName, "binary", path, stdout)
util.CheckError(err, "")
fmt.Printf("The component %s was updated successfully, please use 'odo push' to push your local changes\n", componentName)
odoutil.CheckError(err, "")
log.Successf("The component %s was updated successfully, please use 'odo push' to push your local changes", componentName)
}
},
}
@@ -105,7 +108,7 @@ func NewCmdUpdate() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
updateCmd.Annotations = map[string]string{"command": "component"}
updateCmd.SetUsageTemplate(util.CmdUsageTemplate)
updateCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
//Adding `--application` flag
genericclioptions.AddApplicationFlag(updateCmd)

View File

@@ -1,14 +1,15 @@
package component
import (
"fmt"
"net/url"
"os"
"runtime"
"github.com/golang/glog"
"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/component"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/util"
"github.com/spf13/cobra"
@@ -45,8 +46,8 @@ var watchCmd = &cobra.Command{
componentName, err = component.GetCurrent(applicationName, projectName)
odoutil.CheckError(err, "")
if componentName == "" {
fmt.Println("No component is set as active.")
fmt.Println("Use 'odo component set <component name> to set and existing component as active or call this command with component name as and argument.")
log.Infof("No component is set as active.")
log.Infof("Use 'odo component set <component name> to set and existing component as active or call this command with component name as and argument.")
os.Exit(1)
}
} else {
@@ -57,7 +58,7 @@ var watchCmd = &cobra.Command{
odoutil.CheckError(err, "Unable to get source for %s component.", componentName)
if sourceType != "binary" && sourceType != "local" {
fmt.Printf("Watch is supported by binary and local components only and source type of component %s is %s\n", componentName, sourceType)
log.Errorf("Watch is supported by binary and local components only and source type of component %s is %s", componentName, sourceType)
os.Exit(1)
}
@@ -65,7 +66,7 @@ var watchCmd = &cobra.Command{
odoutil.CheckError(err, "Unable to parse source %s from component %s.", sourcePath, componentName)
if u.Scheme != "" && u.Scheme != "file" {
fmt.Printf("Component %s has invalid source path %s.", componentName, u.Scheme)
log.Errorf("Component %s has invalid source path %s.", componentName, u.Scheme)
os.Exit(1)
}
watchPath := util.ReadFilePath(u, runtime.GOOS)

View File

@@ -2,7 +2,7 @@ package login
import (
"github.com/redhat-developer/odo/pkg/auth"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/spf13/cobra"
)
@@ -40,7 +40,7 @@ var loginCmd = &cobra.Command{
}
err := auth.Login(server, userName, password, token, caAuth, skipTLS)
if err != nil {
util.CheckError(err, "")
odoutil.CheckError(err, "")
}
},
}
@@ -49,7 +49,7 @@ var loginCmd = &cobra.Command{
func NewCmdLogin() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
loginCmd.Annotations = map[string]string{"command": "utility"}
loginCmd.SetUsageTemplate(util.CmdUsageTemplate)
loginCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
loginCmd.Flags().StringVarP(&userName, "username", "u", userName, "username, will prompt if not provided")
loginCmd.Flags().StringVarP(&password, "password", "p", password, "password, will prompt if not provided")
loginCmd.Flags().StringVarP(&token, "token", "t", token, "token, will prompt if not provided")

View File

@@ -1,10 +1,11 @@
package logout
import (
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
"github.com/spf13/cobra"
"os"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/spf13/cobra"
)
var logoutCmd = &cobra.Command{
@@ -19,7 +20,7 @@ var logoutCmd = &cobra.Command{
context := genericclioptions.NewContext(cmd)
client := context.Client
err := client.RunLogout(os.Stdout)
util.CheckError(err, "")
odoutil.CheckError(err, "")
},
}
@@ -27,7 +28,7 @@ var logoutCmd = &cobra.Command{
func NewCmdLogout() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
logoutCmd.Annotations = map[string]string{"command": "utility"}
logoutCmd.SetUsageTemplate(util.CmdUsageTemplate)
logoutCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
return logoutCmd
}

View File

@@ -2,12 +2,14 @@ package project
import (
"fmt"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/odo/util/completion"
"os"
"strings"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/odo/util/completion"
"github.com/redhat-developer/odo/pkg/project"
"github.com/spf13/cobra"
)
@@ -53,21 +55,21 @@ var projectSetCmd = &cobra.Command{
current := context.Project
exists, err := project.Exists(client, projectName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
if !exists {
fmt.Printf("The project %s does not exist\n", projectName)
log.Errorf("The project %s does not exist", projectName)
os.Exit(1)
}
err = project.SetCurrent(client, projectName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
if projectShortFlag {
fmt.Print(projectName)
} else {
if current == projectName {
fmt.Printf("Already on project : %v\n", projectName)
log.Infof("Already on project : %v", projectName)
} else {
fmt.Printf("Switched to project : %v\n", projectName)
log.Infof("Switched to project : %v", projectName)
}
}
},
@@ -88,7 +90,7 @@ var projectGetCmd = &cobra.Command{
if projectShortFlag {
fmt.Print(project)
} else {
fmt.Printf("The current project is: %v\n", project)
log.Infof("The current project is: %v", project)
}
},
}
@@ -105,10 +107,10 @@ var projectCreateCmd = &cobra.Command{
projectName := args[0]
client := genericclioptions.Client(cmd)
err := project.Create(client, projectName)
util.CheckError(err, "")
odoutil.CheckError(err, "")
err = project.SetCurrent(client, projectName)
util.CheckError(err, "")
fmt.Printf("New project created and now using project : %v\n", projectName)
odoutil.CheckError(err, "")
log.Successf("New project created and now using project : %v", projectName)
},
}
@@ -126,9 +128,9 @@ var projectDeleteCmd = &cobra.Command{
// Validate existence of the project to be deleted
isValidProject, err := project.Exists(client, projectName)
util.CheckError(err, "Failed to delete project %s", projectName)
odoutil.CheckError(err, "Failed to delete project %s", projectName)
if !isValidProject {
fmt.Printf("The project %s does not exist. Please check the list of projects using `odo project list`\n", projectName)
log.Errorf("The project %s does not exist. Please check the list of projects using `odo project list`", projectName)
os.Exit(1)
}
@@ -136,28 +138,27 @@ var projectDeleteCmd = &cobra.Command{
if projectForceDeleteFlag {
confirmDeletion = "y"
} else {
fmt.Printf("Are you sure you want to delete project %v? [y/N] ", projectName)
log.Askf("Are you sure you want to delete project %v? [y/N]: ", projectName)
fmt.Scanln(&confirmDeletion)
}
if strings.ToLower(confirmDeletion) != "y" {
fmt.Printf("Aborting deletion of project: %v\n", projectName)
log.Errorf("Aborting deletion of project: %v", projectName)
os.Exit(1)
}
fmt.Printf("Deleting project %s...\n(this operation may take some time)\n", projectName)
currentProject, err := project.Delete(client, projectName)
if err != nil {
util.CheckError(err, "")
odoutil.CheckError(err, "")
}
fmt.Printf("Deleted project : %v\n", projectName)
if currentProject != "" {
fmt.Printf("%s has been set as the active project\n", currentProject)
log.Infof("%s has been set as the active project\n", currentProject)
} else {
// oc errors out as "error: you do not have rights to view project "$deleted_project"."
fmt.Printf("You are not a member of any projects. You can request a project to be created using the `odo project create <project_name>` command\n")
log.Infof("You are not a member of any projects. You can request a project to be created using the `odo project create <project_name>` command")
}
},
@@ -174,10 +175,10 @@ var projectListCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
client := genericclioptions.Client(cmd)
projects, err := project.List(client)
util.CheckError(err, "")
odoutil.CheckError(err, "")
if len(projects) == 0 {
fmt.Println("You are not a member of any projects. You can request a project to be created using the `odo project create <project_name>` command")
return
log.Errorf("You are not a member of any projects. You can request a project to be created using the `odo project create <project_name>` command")
os.Exit(1)
}
fmt.Printf("ACTIVE NAME\n")
for _, project := range projects {
@@ -207,7 +208,7 @@ func NewCmdProject() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
projectCmd.Annotations = map[string]string{"command": "other"}
projectCmd.SetUsageTemplate(util.CmdUsageTemplate)
projectCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
completion.RegisterCommandHandler(projectSetCmd, completion.ProjectNameCompletionHandler)
completion.RegisterCommandHandler(projectDeleteCmd, completion.ProjectNameCompletionHandler)

View File

@@ -1,6 +1,9 @@
package service
import (
"sort"
"testing"
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
"github.com/posener/complete"
componentlabels "github.com/redhat-developer/odo/pkg/component/labels"
@@ -11,8 +14,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
ktesting "k8s.io/client-go/testing"
"sort"
"testing"
)
func TestCompletions(t *testing.T) {

View File

@@ -2,15 +2,17 @@ package storage
import (
"fmt"
"os"
"strings"
"text/tabwriter"
"github.com/pkg/errors"
"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/occlient"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/odo/util/completion"
"os"
"strings"
"text/tabwriter"
"github.com/redhat-developer/odo/pkg/storage"
"github.com/redhat-developer/odo/pkg/util"
@@ -61,7 +63,7 @@ var storageCreateCmd = &cobra.Command{
_, err = storage.Create(client, storageName, storageSize, storagePath, componentName, applicationName)
odoutil.CheckError(err, "")
fmt.Printf("Added storage %v to %v\n", storageName, componentName)
log.Successf("Added storage %v to %v", storageName, componentName)
},
}
@@ -99,7 +101,7 @@ var storageUnmountCmd = &cobra.Command{
storageName, err = storage.GetStorageNameFromMountPath(client, path, componentName, applicationName)
odoutil.CheckError(err, "Unable to get storage name from mount path")
if storageName == "" {
fmt.Printf("No storage is mounted to %s in the component %s\n", path, componentName)
log.Errorf("No storage is mounted to %s in the component %s", path, componentName)
os.Exit(1)
}
} else {
@@ -107,7 +109,7 @@ var storageUnmountCmd = &cobra.Command{
exists, err := storage.IsMounted(client, storageName, componentName, applicationName)
odoutil.CheckError(err, "Unable to check if storage is mounted or not")
if !exists {
fmt.Printf("Storage %v does not exist in component %v\n", storageName, componentName)
log.Errorf("Storage %v does not exist in component %v", storageName, componentName)
os.Exit(1)
}
}
@@ -115,7 +117,7 @@ var storageUnmountCmd = &cobra.Command{
err = storage.Unmount(client, storageName, componentName, applicationName, true)
odoutil.CheckError(err, "Unable to unmount storage %v from component %v", storageName, componentName)
fmt.Printf("Unmounted storage %v from %v\n", storageName, componentName)
log.Infof("Unmounted storage %v from %v", storageName, componentName)
},
}
@@ -140,7 +142,7 @@ var storageDeleteCmd = &cobra.Command{
odoutil.CheckError(err, "")
if !exists {
fmt.Printf("The storage %v does not exists in the application %v\n", storageName, applicationName)
log.Errorf("The storage %v does not exists in the application %v", storageName, applicationName)
os.Exit(1)
}
@@ -155,9 +157,9 @@ var storageDeleteCmd = &cobra.Command{
} else {
if componentName != "" {
mPath := storage.GetMountPath(client, storageName, componentName, applicationName)
fmt.Printf("Are you sure you want to delete the storage %v mounted to %v in %v component? [y/N] ", storageName, mPath, componentName)
log.Askf("Are you sure you want to delete the storage %v mounted to %v in %v component? [y/N]: ", storageName, mPath, componentName)
} else {
fmt.Printf("Are you sure you want to delete the storage %v that is not currently mounted to any component? [y/N] ", storageName)
log.Askf("Are you sure you want to delete the storage %v that is not currently mounted to any component? [y/N]: ", storageName)
}
fmt.Scanln(&confirmDeletion)
}
@@ -165,12 +167,13 @@ var storageDeleteCmd = &cobra.Command{
componentName, err = storage.Delete(client, storageName, applicationName)
odoutil.CheckError(err, "failed to delete storage")
if componentName != "" {
fmt.Printf("Deleted storage %v from %v\n", storageName, componentName)
log.Infof("Deleted storage %v from %v", storageName, componentName)
} else {
fmt.Printf("Deleted storage %v\n", storageName)
log.Infof("Deleted storage %v", storageName)
}
} else {
fmt.Printf("Aborting deletion of storage: %v\n", storageName)
log.Errorf("Aborting deletion of storage: %v", storageName)
os.Exit(1)
}
},
}
@@ -230,12 +233,12 @@ var storageMountCmd = &cobra.Command{
isMounted, err := storage.IsMounted(client, storageName, componentName, applicationName)
odoutil.CheckError(err, "unable to check if the component is already mounted or not")
if isMounted {
fmt.Printf("The storage %v is already mounted on the current component '%v'\n", storageName, componentName)
log.Errorf("The storage %v is already mounted on the current component '%v'", storageName, componentName)
os.Exit(1)
}
err = storage.Mount(client, storagePath, storageName, componentName, applicationName)
odoutil.CheckError(err, "")
fmt.Printf("The storage %v is successfully mounted to the current component '%v'\n", storageName, componentName)
log.Infof("The storage %v is successfully mounted to the current component '%v'", storageName, componentName)
},
}

View File

@@ -8,7 +8,9 @@ import (
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util/completion"
"github.com/redhat-developer/odo/pkg/log"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/util"
"text/tabwriter"
@@ -68,23 +70,23 @@ The created URL can be used to access the specified component from outside the O
case 1:
urlName = args[0]
default:
fmt.Println("unable to get component")
log.Errorf("unable to get component")
os.Exit(1)
}
exists, err := url.Exists(client, urlName, "", applicationName)
if exists {
fmt.Printf("The url %s already exists in the application: %s\n", urlName, applicationName)
log.Errorf("The url %s already exists in the application: %s", urlName, applicationName)
os.Exit(1)
}
fmt.Printf("Adding URL to component: %v\n", componentName)
log.Infof("Adding URL to component: %v", componentName)
urlRoute, err := url.Create(client, urlName, urlPort, componentName, applicationName)
odoutil.CheckError(err, "")
urlCreated := url.GetURLString(*urlRoute)
fmt.Printf("URL created for component: %v\n\n"+
log.Successf("URL created for component: %v\n\n"+
"%v - %v\n", componentName, urlRoute.Name, urlCreated)
if urlOpenFlag {
@@ -114,7 +116,7 @@ var urlDeleteCmd = &cobra.Command{
odoutil.CheckError(err, "")
if !exists {
fmt.Printf("The URL %s does not exist within the component %s\n", urlName, componentName)
log.Errorf("The URL %s does not exist within the component %s", urlName, componentName)
os.Exit(1)
}
@@ -122,7 +124,7 @@ var urlDeleteCmd = &cobra.Command{
if urlForceDeleteFlag {
confirmDeletion = "y"
} else {
fmt.Printf("Are you sure you want to delete the url %v? [y/N] ", urlName)
log.Askf("Are you sure you want to delete the url %v? [y/N]: ", urlName)
fmt.Scanln(&confirmDeletion)
}
@@ -130,9 +132,10 @@ var urlDeleteCmd = &cobra.Command{
err = url.Delete(client, urlName, applicationName)
odoutil.CheckError(err, "")
fmt.Printf("Deleted URL: %v\n", urlName)
log.Infof("Deleted URL: %v", urlName)
} else {
fmt.Printf("Aborting deletion of url: %v\n", urlName)
log.Errorf("Aborting deletion of url: %v", urlName)
os.Exit(1)
}
},
}
@@ -155,9 +158,9 @@ var urlListCmd = &cobra.Command{
odoutil.CheckError(err, "")
if len(urls) == 0 {
fmt.Printf("No URLs found for component %v in application %v\n", componentName, applicationName)
log.Errorf("No URLs found for component %v in application %v", componentName, applicationName)
} else {
fmt.Printf("Found the following URLs for component %v in application %v:\n", componentName, applicationName)
log.Infof("Found the following URLs for component %v in application %v:", componentName, applicationName)
tabWriterURL := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)

View File

@@ -8,6 +8,8 @@ import (
"github.com/pkg/errors"
"github.com/redhat-developer/odo/pkg/config"
"github.com/redhat-developer/odo/pkg/log"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/spf13/cobra"
)
@@ -28,7 +30,8 @@ Timeout - Timeout (in seconds) for OpenShift server connection check`,
// 'odo utils config' is the same as 'odo utils config --help'
Args: func(cmd *cobra.Command, args []string) error {
if len(args) >= 1 && args[0] != "view" && args[0] != "set" {
return fmt.Errorf(`Unknown command, use "set" or "view"`)
log.Errorf(`Unknown command, use "set" or "view"`)
os.Exit(1)
}
return nil
}, Run: func(cmd *cobra.Command, args []string) {
@@ -86,7 +89,7 @@ var configurationViewCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cfg, err := config.New()
if err != nil {
fmt.Println(err, ": unable to view configuration")
odoutil.CheckError(err, "unable to view configuration")
}
w := tabwriter.NewWriter(os.Stdout, 5, 2, 2, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, "PARAMETER", "\t", "CURRENT_VALUE")

View File

@@ -1,11 +1,11 @@
package utils
import (
"fmt"
"github.com/redhat-developer/odo/pkg/odo/util"
"io"
"os"
"github.com/redhat-developer/odo/pkg/log"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/spf13/cobra"
)
@@ -25,7 +25,7 @@ This will append your PS1 environment variable with Odo component and applicatio
RunE: func(cmd *cobra.Command, args []string) error {
err := TerminalGenerate(os.Stdout, cmd, args)
util.CheckError(err, "")
odoutil.CheckError(err, "")
return nil
},
@@ -35,10 +35,12 @@ This will append your PS1 environment variable with Odo component and applicatio
func TerminalGenerate(out io.Writer, cmd *cobra.Command, args []string) error {
// Check the passed in arguments
if len(args) == 0 {
return fmt.Errorf("Shell not specified. ex. odo completion [bash|zsh]")
log.Error("Shell not specified. ex. odo completion [bash|zsh]")
os.Exit(1)
}
if len(args) > 1 {
return fmt.Errorf("Too many arguments. Expected only the shell type. ex. odo completion [bash|zsh]")
log.Error("Too many arguments. Expected only the shell type. ex. odo completion [bash|zsh]")
os.Exit(1)
}
shell := args[0]
@@ -82,7 +84,8 @@ PROMPT='$(__odo_ps1)'$PROMPT
} else if shell == "zsh" {
out.Write([]byte(zshPS1Output))
} else {
return fmt.Errorf("not a compatible shell, bash and zsh are only supported")
log.Errorf("not a compatible shell, bash and zsh are only supported")
os.Exit(1)
}
return nil

View File

@@ -2,6 +2,7 @@ package utils
import (
"fmt"
"github.com/redhat-developer/odo/pkg/odo/util"
"github.com/spf13/cobra"

View File

@@ -2,11 +2,14 @@ package version
import (
"fmt"
"os"
"strings"
"github.com/redhat-developer/odo/pkg/notify"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/util"
"os"
"strings"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/golang/glog"
"github.com/spf13/cobra"
@@ -47,7 +50,7 @@ var versionCmd = &cobra.Command{
if !clientFlag {
// Lets fetch the info about the server
serverInfo, err := genericclioptions.ClientWithConnectionCheck(cmd, true).GetServerVersion()
util.CheckError(err, "")
odoutil.CheckError(err, "")
// make sure we only include Openshift info if we actually have it
openshiftStr := ""
if len(serverInfo.OpenShiftVersion) > 0 {

View File

@@ -2,6 +2,7 @@ package genericclioptions
import (
"fmt"
"github.com/golang/glog"
"github.com/redhat-developer/odo/pkg/application"
"github.com/redhat-developer/odo/pkg/component"

View File

@@ -22,7 +22,6 @@ func CheckError(err error, context string, a ...interface{}) {
} else {
fmt.Printf(fmt.Sprintf("%s\n", context), a...)
}
os.Exit(1)
}
}

View File

@@ -2,6 +2,7 @@ package util
import (
"fmt"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/validation"
"strings"

View File

@@ -4,6 +4,7 @@ import (
"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/redhat-developer/odo/pkg/config"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/occlient"
)
@@ -56,6 +57,10 @@ func Create(client *occlient.Client, projectName string) error {
// Delete deletes the project with name projectName and sets any other remaining project as the current project
// and returns the current project or "" if no current project is set and errors if any
func Delete(client *occlient.Client, projectName string) (string, error) {
// Loading spinner
s := log.Spinnerf("Deleting project %s", projectName)
defer s.End(false)
currentProject := GetCurrent(client)
projects, err := List(client)
@@ -116,6 +121,8 @@ func Delete(client *occlient.Client, projectName string) (string, error) {
// Nothing to do if there's no project left -- Default oc client way
glog.V(4).Info("No projects available to mark as current\n")
}
s.End(true)
return currentProject, nil
}

View File

@@ -2,6 +2,7 @@ package secret
import (
"fmt"
"github.com/redhat-developer/odo/pkg/occlient"
corev1 "k8s.io/api/core/v1"
"strings"

View File

@@ -3,9 +3,10 @@ package service
import (
"encoding/json"
"fmt"
appsv1 "github.com/openshift/api/apps/v1"
"strings"
appsv1 "github.com/openshift/api/apps/v1"
"sort"
"github.com/pkg/errors"

View File

@@ -3,6 +3,7 @@ package service
import (
"encoding/json"
"fmt"
scv1beta1 "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
appsv1 "github.com/openshift/api/apps/v1"
"github.com/pkg/errors"

View File

@@ -202,6 +202,7 @@ var _ = Describe("odoCmpE2e", func() {
It("should watch the local sources for any changes", func() {
runCmd("odo create wildfly wildfly-watch --local " + tmpDir + "/katacoda-odo-backend-1 --min-memory 400Mi --max-memory 700Mi")
runCmd("odo push -v 4")
startSimulationCh := make(chan bool)
go func() {
startMsg := <-startSimulationCh