Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nxy7 committed Jun 21, 2023
1 parent d4094ae commit f81a96d
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 187 deletions.
42 changes: 0 additions & 42 deletions cmd/dev.go

This file was deleted.

34 changes: 0 additions & 34 deletions cmd/init.go

This file was deleted.

59 changes: 0 additions & 59 deletions cmd/purge.go

This file was deleted.

15 changes: 3 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"os"
"os/exec"

"optimus/config"

Expand All @@ -30,17 +29,9 @@ func Execute() {
func init() {
AppConfig = config.LoadConfig()

for name, command := range AppConfig.AdditionalCommands {
rootCmd.AddCommand(&cobra.Command{
Use: name,
Short: command.Description,
Run: func(cmd *cobra.Command, args []string) {
e := exec.Command("bash", "-c", command.Run)
e.Stdout = os.Stdout

e.Run()
},
})
for _, command := range AppConfig.AdditionalCommands {
cobraCmd := command.ToCobraCommand()
rootCmd.AddCommand(&cobraCmd)
}

for _, svc := range AppConfig.Services {
Expand Down
34 changes: 0 additions & 34 deletions cmd/run.go

This file was deleted.

26 changes: 24 additions & 2 deletions config/command.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package config

import "log"
import (
"log"
"os"
"os/exec"

"github.com/spf13/cobra"
)

type Cmd struct {
Run string
Name string
Description string
File string
Shell string
}

func ParseCmd(a any) Cmd {
func ParseCmd(name string, a any) Cmd {
command := Cmd{
Run: "",
Name: name,
Description: "",
File: "",
Shell: "bash -c",
Expand Down Expand Up @@ -53,6 +61,20 @@ func ParseCmd(a any) Cmd {
return command
}

func (c *Cmd) ToCobraCommand() cobra.Command {
return cobra.Command{
Use: c.Name,
Short: c.Description,
Run: func(cmd *cobra.Command, args []string) {
e := exec.Command("bash", "-c", c.Run)
e.Stdout = os.Stdout
e.Stderr = os.Stderr

e.Run()
},
}
}

type TestCmd struct {
Cmd Cmd
DependsOn []Service
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func LoadConfigFromPath(p string) Config {
g := ParseGlobal(v2)
conf.Global = &g
} else if k == "e2e_tests" {
c := ParseCmd(v2)
c := ParseCmd(k, v2)
conf.E2eTests = &c
} else if k == "services" {
servicesAny, o := v2.(map[string]any)
Expand All @@ -83,7 +83,7 @@ func LoadConfigFromPath(p string) Config {
conf.Services[svcName] = &s
}
} else {
cmd := ParseCmd(v2)
cmd := ParseCmd(k, v2)
conf.AdditionalCommands[k] = &cmd
}

Expand Down
5 changes: 3 additions & 2 deletions config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ func ParseService(name string, a any) Service {

for k, v := range amap {
if k == "dev" {
c := ParseCmd(v)
c := ParseCmd(k, v)
s.Dev = &c
} else if k == "build" {
c := ParseCmd(v)
c := ParseCmd(k, v)
s.Build = &c
} else if k == "root" {
str := v.(string)
Expand Down Expand Up @@ -77,6 +77,7 @@ func (s *Service) ToCobraCommand() cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
e := exec.Command("bash", "-c", c.Run)
e.Stdout = os.Stdout
e.Stderr = os.Stderr

e.Run()

Expand Down
1 change: 1 addition & 0 deletions optimus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ start:
description: |
Start the application
run: |
echo "sup"
docker compose -f compose.yml -f compose.dev.yml up -d
Expand Down

0 comments on commit f81a96d

Please sign in to comment.