Skip to content

Commit

Permalink
Feature/ubuntu 22 e2e (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcred authored Aug 24, 2022
1 parent 4bc9948 commit db66497
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 66 deletions.
104 changes: 51 additions & 53 deletions internal/app/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,76 +16,74 @@ limitations under the License.
package commands

import (
"fmt"
"github.com/spf13/cobra"
"os"
"os/user"
"titan/internal/app/providers"
"fmt"
"github.com/spf13/cobra"
"os"
"os/user"
"titan/internal/app/providers"
)

var (
context string
provider providers.Provider
version string
verbose bool
force bool
guid string
tags []string
params []string
envVars []string
name string
source string
remote string
updateOnly bool
removeImages bool
var (
context string
provider providers.Provider
version string
verbose bool
force bool
guid string
tags []string
params []string
envVars []string
name string
source string
remote string
updateOnly bool
removeImages bool
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "titan",
Short: "Titan CLI",
Long: `Titan CLI`,
Use: "titan",
Short: "Titan CLI",
Long: `Titan CLI`,
}


// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func init() {
cobra.OnInitialize(initConfig)
cobra.OnInitialize(initConfig)

//Global params
rootCmd.PersistentFlags().StringVar(&context, "context","", "Titan Provider Context")
rootCmd.Version = "0.5.4"
//Global params
rootCmd.PersistentFlags().StringVar(&context, "context", "", "Titan Provider Context")
rootCmd.Version = "0.6.0"
}

// initConfig reads in config file and ENV variables if set.
func initConfig() {
u, _ := user.Current()
titanConfig := u.HomeDir + "/.titan/config"
if _, err := os.Stat(titanConfig); os.IsNotExist(err) {
os.Create(titanConfig)
}
isInstall := false
for _, item := range os.Args {
if item == "install" || item == "ls" {
isInstall = true
}
}
if context != "" {
provider, name = providers.ByName(context)
} else if os.Getenv("TITAN_CONTEXT") != "" {
provider, name = providers.ByName(os.Getenv("TITAN_CONTEXT"))
} else if isInstall {
context = "docker" //TODO confirm valid
} else {
provider = providers.Default()
}
u, _ := user.Current()
titanConfig := u.HomeDir + "/.titan/config"
if _, err := os.Stat(titanConfig); os.IsNotExist(err) {
os.Create(titanConfig)
}
isInstall := false
for _, item := range os.Args {
if item == "install" || item == "ls" {
isInstall = true
}
}
if context != "" {
provider, name = providers.ByName(context)
} else if os.Getenv("TITAN_CONTEXT") != "" {
provider, name = providers.ByName(os.Getenv("TITAN_CONTEXT"))
} else if isInstall {
context = "docker" //TODO confirm valid
} else {
provider = providers.Default()
}
}

24 changes: 12 additions & 12 deletions internal/app/providers/Local.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ var ce = utils.CommandExecutor(60, false)
var user, _ = ce.Exec("git", "config", "user.name")
var email, _ = ce.Exec("git", "config", "user.email")

type local struct{
contextName string
host string
portNum int
type local struct {
contextName string
host string
portNum int
titanServerVersion string
dockerRegistryUrl string
dockerRegistryUrl string
}

func (l local) GetType() string {
Expand Down Expand Up @@ -106,7 +106,7 @@ func (l local) RemoteRemove(repo string, remote string) {
cmn.RemoteRemove(repo, remote, l.portNum)
}

func (l local) Remove (repo string, force bool) {
func (l local) Remove(repo string, force bool) {
lcl.Remove(repo, force, l.portNum, l.contextName)
}

Expand Down Expand Up @@ -144,10 +144,10 @@ func (l local) Upgrade(force bool, version string, finalize bool, path string) {

func Local(contextName string, host string, port int) Provider {
return local{
contextName:contextName,
host:host,
portNum:port,
titanServerVersion: "0.8.5",
dockerRegistryUrl: "titandata",
contextName: contextName,
host: host,
portNum: port,
titanServerVersion: "0.8.7",
dockerRegistryUrl: "titandata",
}
}
}
2 changes: 1 addition & 1 deletion tests/endtoend/context/docker/DockerTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tests:
command: curl -L http://localhost
exitValue: 7
stderr:
contains: "Failed to connect to localhost port 80: Connection refused"
contains: "Connection refused"
- "can remove nginx-test without port mapping":
command: titan rm -f nginx-test
after:
Expand Down

0 comments on commit db66497

Please sign in to comment.