Merge pull request #284 from kadel/use-project-abstraction

use project abstraction
This commit is contained in:
Shubham
2018-04-03 10:22:46 +05:30
committed by GitHub
5 changed files with 21 additions and 35 deletions

View File

@@ -25,13 +25,9 @@ var projectSetCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
projectName := args[0]
client := getOcClient()
current, err := project.GetCurrent(client)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
current := project.GetCurrent(client)
err = project.SetCurrent(client, projectName)
err := project.SetCurrent(client, projectName)
if err != nil {
fmt.Println(err)
os.Exit(1)
@@ -54,11 +50,7 @@ var projectGetCmd = &cobra.Command{
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
client := getOcClient()
project, err := project.GetCurrent(client)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
project := project.GetCurrent(client)
if projectShortFlag {
fmt.Println(project)

View File

@@ -7,6 +7,7 @@ import (
"github.com/redhat-developer/ocdev/pkg/application"
"github.com/redhat-developer/ocdev/pkg/component"
"github.com/redhat-developer/ocdev/pkg/project"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
@@ -29,8 +30,7 @@ var pushCmd = &cobra.Command{
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
client := getOcClient()
// TODO: use project abstraction
projectName := client.GetCurrentProjectName()
projectName := project.GetCurrent(client)
applicationName, err := application.GetCurrent(client)
if err != nil {

View File

@@ -2,9 +2,11 @@ package application
import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/redhat-developer/ocdev/pkg/config"
"github.com/redhat-developer/ocdev/pkg/occlient"
log "github.com/sirupsen/logrus"
"github.com/redhat-developer/ocdev/pkg/project"
)
// ApplicationLabel is label key that is used to group all object that belong to one application
@@ -44,8 +46,7 @@ func GetLabels(application string, additional bool) (map[string]string, error) {
// Create a new application
func Create(client *occlient.Client, applicationName string) error {
// TODO: use project abstraction
project := client.GetCurrentProjectName()
project := project.GetCurrent(client)
cfg, err := config.New()
if err != nil {
@@ -66,8 +67,7 @@ func Create(client *occlient.Client, applicationName string) error {
func List(client *occlient.Client) ([]config.ApplicationInfo, error) {
applications := []config.ApplicationInfo{}
// TODO: use project abstaction
project := client.GetCurrentProjectName()
project := project.GetCurrent(client)
cfg, err := config.New()
if err != nil {
@@ -129,7 +129,8 @@ func Delete(client *occlient.Client, name string) error {
if err != nil {
return errors.Wrapf(err, "unable to delete application %s", name)
}
project := client.GetCurrentProjectName()
project := project.GetCurrent(client)
err = cfg.DeleteApplication(name, project)
if err != nil {
@@ -143,8 +144,7 @@ func Delete(client *occlient.Client, name string) error {
// GetCurrent returns currently active application.
// If no application is active this functions returns empty string
func GetCurrent(client *occlient.Client) (string, error) {
// TODO: use project abstaction
project := client.GetCurrentProjectName()
project := project.GetCurrent(client)
cfg, err := config.New()
if err != nil {
@@ -171,12 +171,9 @@ func GetCurrentOrDefault(client *occlient.Client) (string, error) {
// SetCurrent set application as active
func SetCurrent(client *occlient.Client, name string) error {
// TODO: right now this assumes that there is a current project in openshift
// when we have project support in ocdev, this should call project.GetCurrent()
// TODO: use project abstraction
log.Debugf("Setting application %s as current.\n", name)
project := client.GetCurrentProjectName()
project := project.GetCurrent(client)
cfg, err := config.New()
if err != nil {

View File

@@ -11,6 +11,7 @@ import (
"github.com/redhat-developer/ocdev/pkg/application"
"github.com/redhat-developer/ocdev/pkg/config"
"github.com/redhat-developer/ocdev/pkg/occlient"
"github.com/redhat-developer/ocdev/pkg/project"
)
// ComponentLabel is a label key used to identify component
@@ -134,7 +135,7 @@ func Delete(client *occlient.Client, name string) (string, error) {
return "", errors.Wrapf(err, "unable to delete component %s", name)
}
currentProject := client.GetCurrentProjectName()
currentProject := project.GetCurrent(client)
cfg, err := config.New()
if err != nil {
@@ -165,7 +166,7 @@ func SetCurrent(client *occlient.Client, name string) error {
return errors.Wrapf(err, "unable to set current component %s", name)
}
currentProject := client.GetCurrentProjectName()
currentProject := project.GetCurrent(client)
currentApplication, err := application.GetCurrent(client)
if err != nil {
@@ -192,8 +193,7 @@ func GetCurrent(client *occlient.Client) (string, error) {
return "", errors.Wrap(err, "unable to get active application")
}
currentProject := client.GetCurrentProjectName()
currentProject := project.GetCurrent(client)
currentComponent := cfg.GetActiveComponent(currentApplication, currentProject)
return currentComponent, nil
@@ -244,8 +244,7 @@ func GetComponentType(client *occlient.Client, componentName string, application
// List lists components in active application
func List(client *occlient.Client) ([]ComponentInfo, error) {
// TODO: use project abstaction
currentProject := client.GetCurrentProjectName()
currentProject := project.GetCurrent(client)
currentApplication, err := application.GetCurrent(client)
if err != nil {

View File

@@ -13,11 +13,9 @@ type ProjectInfo struct {
Active bool
}
func GetCurrent(client *occlient.Client) (string, error) {
// TODO: use project abstaction
func GetCurrent(client *occlient.Client) string {
project := client.GetCurrentProjectName()
return project, nil
return project
}
func SetCurrent(client *occlient.Client, project string) error {