Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/cca/cca.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cloud-ca/cca/cmd/cca/completion"
"github.com/cloud-ca/cca/cmd/cca/version"
"github.com/cloud-ca/cca/pkg/cli"
"github.com/cloud-ca/cca/pkg/client"
"github.com/cloud-ca/cca/pkg/flags"
"github.com/cloud-ca/cca/pkg/output"
"github.com/sirupsen/logrus"
Expand All @@ -44,7 +45,9 @@ func NewCommand() *cobra.Command {
if err := flg.Normalize(cmd, viper.Get, args); err != nil {
return err
}
cli.Flags = flg
cli.GlobalFlags = flg
cli.OutputBuilder = output.NewBuilder(flg.OutputFormat, flg.OutputColored)
cli.CcaClient = client.NewClient(flg.APIURL, flg.APIKey)
return nil
},
}
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ module github.com/cloud-ca/cca
go 1.12

require (
github.com/cloud-ca/go-cloudca v1.4.0
github.com/lithammer/dedent v1.1.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.4.0
github.com/tidwall/pretty v1.0.0
gopkg.in/yaml.v2 v2.2.2
sigs.k8s.io/kind v0.4.0
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloud-ca/go-cloudca v1.4.0 h1:R8ZWca1EtZrMS3t05Un11LwGX21/phuPp7kpMNT82DU=
github.com/cloud-ca/go-cloudca v1.4.0/go.mod h1:+BpT2i2e5Zn+IDBVcZiqOBrZXSQpo/ObZ/MMTUh/RhI=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
Expand All @@ -21,6 +23,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
Expand All @@ -47,6 +50,7 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -131,9 +135,13 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
Expand Down Expand Up @@ -168,6 +176,7 @@ golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
6 changes: 5 additions & 1 deletion pkg/cli/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
package cli

import (
"github.com/cloud-ca/cca/pkg/client"
"github.com/cloud-ca/cca/pkg/flags"
"github.com/cloud-ca/cca/pkg/output"
)

// Wrapper of different parts of cca cli
type Wrapper struct {
Flags *flags.GlobalFlags
GlobalFlags *flags.GlobalFlags
OutputBuilder *output.Builder
CcaClient *client.Client
}
33 changes: 33 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright © 2019 cloud.ca 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.

// Package client contains the client library to interact with cloud.ca infrastructure
package client

import (
gocca "github.com/cloud-ca/go-cloudca"
)

// Client to interact with cloud.ca infrastructure
type Client struct {
*gocca.CcaClient
}

// NewClient returns a new client to interact with cloud.ca
// infrastructure with provided API URL and Key
func NewClient(url string, key string) *Client {
return &Client{
CcaClient: gocca.NewCcaClientWithURL(url, key),
}
}
41 changes: 41 additions & 0 deletions pkg/output/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright © 2019 cloud.ca 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.

// Package output contains helper utility to build and format the output
package output

// Builder is used to prepare the output. It internally
// create a Formatter and use it to print the 'object'
// to different formats and colors (based on the flags)
type Builder struct {
format string
colored bool
}

// NewBuilder returns a new output.Builder with desired format and colored output
func NewBuilder(format string, colored bool) *Builder {
return &Builder{
format: format,
colored: colored,
}
}

// Build builds the callback function to be used directly in cobra.Command
// in order not to pass around private structs from go-cloudca library
func (b *Builder) Build(fn func(*Formatter) error) error {
formatter := &Formatter{
builder: b,
}
return fn(formatter)
}
74 changes: 74 additions & 0 deletions pkg/output/formatter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright © 2019 cloud.ca 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.

// Package output contains helper utility to build and format the output
package output

import (
"encoding/json"
"fmt"

"github.com/tidwall/pretty"
yaml "gopkg.in/yaml.v2"
)

// Formatter is used to format retrieved object to selected
// format and print it out on STDOUT and also colorized it
// if the flag is set.
type Formatter struct {
builder *Builder
}

// Format prints the representation of input 'object' to
// STDOUT based on the requested 'format' (JSON or YAML).
// The output will also be colorized if flag is set.
func (f *Formatter) Format(object interface{}) error {
builder := f.builder
if builder.format == "json" {
return f.toJSON(object, builder)
} else if builder.format == "yaml" {
return f.toYAML(object, builder)
}
return nil
}

// toJSON prints the JSON representation of input 'object'
// to STDOUT. The output will be colorized if flag is set.
func (f *Formatter) toJSON(object interface{}, builder *Builder) error {
jsoned, err := json.Marshal(object)
if err != nil {
return err
}
jsoned = pretty.Pretty(jsoned)
if builder.colored {
jsoned = pretty.Color(jsoned, nil)
}
_, err = fmt.Printf("%s", jsoned)
return err
}

// toYAML prints the YAML representation of input 'object'
// to STDOUT. The output will be colorized if flag is set.
func (f *Formatter) toYAML(object interface{}, builder *Builder) error {
yamled, err := yaml.Marshal(object)
if err != nil {
return err
}
// TODO colorize yaml
// if builder.colored {
// yamled = Color(yamled, nil)
// }
_, err = fmt.Printf("%s", yamled)
return err
}
4 changes: 2 additions & 2 deletions pkg/output/util.go → pkg/output/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package output contains helper utility to build and format the output
package output

import (
Expand All @@ -20,7 +21,7 @@ import (

var outputFormats = []string{"json", "yaml"}

// Get return available output formats
// Get returns available output formats
func Get() []string {
return outputFormats
}
Expand Down Expand Up @@ -49,5 +50,4 @@ func FormatStrings() string {
}
b.WriteString("]")
return b.String()

}
27 changes: 27 additions & 0 deletions vendor/github.com/cloud-ca/go-cloudca/.gometalinter.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/cloud-ca/go-cloudca/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading