Skip to content

Commit

Permalink
Merge pull request #21 from rubixFunctions/code-clean
Browse files Browse the repository at this point in the history
Code Refactor
  • Loading branch information
ciaranRoche authored Apr 19, 2019
2 parents 93d2d1f + 28319a2 commit abdb65d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
5 changes: 3 additions & 2 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func init() {

// Create function, builds tar of directory and execute Build Function
func create(name string, push bool, quay bool) {
fmt.Println("RubiX is starting to build function image")
wd, err := os.Getwd()
if err != nil {
panic(err)
Expand All @@ -82,6 +83,7 @@ func create(name string, push bool, quay bool) {
return
}
pass := getPass()
fmt.Println("Creating function tar")
tar := new(archivex.TarFile)
err = tar.Create("/tmp/archieve.tar")
if err != nil {
Expand All @@ -105,7 +107,6 @@ func create(name string, push bool, quay bool) {
defer dockerBuildContext.Close()

cli, _ := client.NewClientWithOpts(client.FromEnv)

buildImage(imageName, cli, dockerBuildContext)

if push {
Expand Down Expand Up @@ -177,7 +178,7 @@ func genServiceYaml(name string, image string){

// Get user password
func getPass() string {
fmt.Print("Enter Password: ")
fmt.Print("Enter Password for Image Hub: ")
bytePass, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
panic(err)
Expand Down
15 changes: 14 additions & 1 deletion cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ spec:
fmt.Println(err)
}

fmt.Println("service.yaml generated")
fmt.Println("Push completed and service.yaml generated")
}

var logo =`
______ _ ___ __
| ___ \ | | (_) \ / /
| |_/ / _| |__ _ \ V /
| / | | | '_ \| |/ \
| |\ \ |_| | |_) | / /^\ \
\_| \_\__,_|_.__/|_\/ \/
`

func initString(t string) {
fmt.Println(fmt.Sprintf("Building %v Scaffolding", t))
}
14 changes: 9 additions & 5 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ var initCmd = &cobra.Command{
Use: "init [function name]",
Aliases: []string{"initialize", "initialise", "create"},
Short: "Initialize a Function as a Container",
Long: `Initialize (r3x init) will create a new Function as a container,
Long: fmt.Sprintf(`%v Initialize (r3x init) will create a new Function as a container,
with a license and the appropriate structure needed for a Knative Function.
- If an absolute path is provided, it will be created.
Init will not use an existing directory with contents.`,
Init will not use an existing directory with contents.`, logo),
Run: func(cmd *cobra.Command, args []string) {
// get flag values
license := cmd.Flag("license").Value.String()
Expand All @@ -46,11 +46,12 @@ Init will not use an existing directory with contents.`,
log.Print(err)
}
// Switch on different function type flag
fmt.Println("Checking Params")
switch name {
case "js":
var function *Function
if len(args) == 0 {
fmt.Println("Function name needed")
fmt.Println("A Function needs a name")
} else if len(args) == 1 {
arg := args[0]
if arg[0] == '.' {
Expand All @@ -60,12 +61,13 @@ Init will not use an existing directory with contents.`,
function.license.Name = license
var schema *Schema
schema = NewSchema("r3x-"+arg, "js", "json")
initString("JavaScript")
InitializeJSFunction(function, schema)
}
case "go":
var function *Function
if len(args) == 0 {
fmt.Println("Function name needed")
fmt.Println("A Function needs a name")
} else if len(args) == 1 {
arg := args[0]
if arg[0] == '.' {
Expand All @@ -75,12 +77,13 @@ Init will not use an existing directory with contents.`,
function.license.Name = license
var schema *Schema
schema = NewSchema("r3x-"+arg, "go", "json")
initString("GoLang")
InitializeGoFunction(function, schema)
}
case "py":
var function *Function
if len(args) == 0 {
fmt.Println("Function name needed")
fmt.Println("A Function needs a name")
} else if len(args) == 1 {
arg := args[0]
if arg[0] == '.' {
Expand All @@ -90,6 +93,7 @@ Init will not use an existing directory with contents.`,
function.license.Name = license
var schema *Schema
schema = NewSchema("r3x-"+arg, "py", "json")
initString("Python")
InitializePyFunction(function, schema)
}
default:
Expand Down
12 changes: 5 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@ package cmd

import (
"fmt"
"os"

homedir "github.com/mitchellh/go-homedir"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
)

var cfgFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "r3x",
Short: "Creating Functions as a Container",
Long: `
RubiX CLI allows for the creation of Functions as a Container.
Short: fmt.Sprintf("%v Creating Functions as a Container", logo),
Long: fmt.Sprintf(`%v RubiX CLI allows for the creation of Functions as a Container.
It provides the tools needed that abstract the mundane tasks,
so that, you can focus on your functions logic.`,
so that, you can focus on your functions logic.`, logo),

// Run: func(cmd *cobra.Command, args []string) { },
}
Expand Down

0 comments on commit abdb65d

Please sign in to comment.