-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa14bda
commit bc0766f
Showing
9 changed files
with
126 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package stack | ||
|
||
#ComponentID: string & =~"^[a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])?$" | ||
|
||
#Variable: { | ||
name: string | ||
value: string | ||
} | ||
|
||
#Component: { | ||
id: #ComponentID | ||
path: string | *id | ||
depends_on: [...#Component.id] | ||
variables: [...#Variable] | ||
} | ||
|
||
#Stack: [ID=_]: { | ||
id: ID | ||
components: [...#Component] | ||
component_overrides: [ComponentID=_]: { | ||
workspaces: [...string] | ||
} | ||
} | ||
|
||
component: [ID=_]: #Component & {id: ID} | ||
|
||
stack: #Stack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package config | ||
|
||
import "fmt" | ||
|
||
type Config struct { | ||
Component map[ComponentID]Component `json:"component"` | ||
Stack map[string]Stack `json:"stack"` | ||
} | ||
|
||
type Component struct { | ||
ID ComponentID `json:"id"` | ||
Path string `json:"path"` | ||
DependsOn []string `json:"depends_on"` | ||
Variables []Variable `json:"variables"` | ||
} | ||
|
||
type ComponentID string | ||
|
||
type Variable struct { | ||
Name string `json:"name"` | ||
Value string `json:"value"` | ||
} | ||
|
||
type Stack struct { | ||
ID string `json:"id"` | ||
Components []Component `json:"components"` | ||
ComponentOverrides map[string]struct { | ||
Workspaces []string | ||
} `json:"component_overrides"` | ||
} | ||
|
||
func (c Component) String() string { | ||
return fmt.Sprintf("id: %s, path: %s, depends_on: %v, variables: %v", c.ID, c.Path, c.DependsOn, c.Variables) | ||
} | ||
|
||
func (s Stack) String() string { | ||
return fmt.Sprintf("id: %s, components: %v, component_overrides: %v", s.ID, s.Components, s.ComponentOverrides) | ||
} | ||
|
||
func (v Variable) String() string { | ||
return fmt.Sprintf("%s=%s", v.Name, v.Value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package stack | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/DavidGamba/dgtools/bt/stack/config" | ||
"github.com/DavidGamba/go-getoptions" | ||
) | ||
|
||
func GraphCMD(parent *getoptions.GetOpt) *getoptions.GetOpt { | ||
opt := parent.NewCommand("graph", "Visual representation of the project layers DAG") | ||
opt.SetCommandFn(GraphRun) | ||
opt.Bool("reverse", false, opt.Description("Reverses the order of operation")) | ||
opt.String("T", "", opt.Description("Set output format. For example: -T png")) | ||
opt.String("filename", "project-graph.png") | ||
return opt | ||
} | ||
|
||
func GraphRun(ctx context.Context, opt *getoptions.GetOpt, args []string) error { | ||
configFile := opt.Value("config").(string) | ||
|
||
cfg, _, err := config.Get(ctx, configFile) | ||
if err != nil { | ||
return fmt.Errorf("failed to get project config: %w", err) | ||
} | ||
|
||
for _, c := range cfg.Component { | ||
Logger.Printf("component: %s\n", c) | ||
} | ||
|
||
for _, s := range cfg.Stack { | ||
Logger.Printf("stack: %s\n", s) | ||
for _, c := range s.Components { | ||
Logger.Printf("%s\n", c) | ||
} | ||
// fmt.Printf("\tlayers\n") | ||
// for _, v := range v.Components { | ||
// fmt.Printf("\t\t%s\n", v) | ||
// } | ||
// fmt.Printf("\tlayer_overrides\n") | ||
// for k, v := range v.ComponentOverrides { | ||
// fmt.Printf("\t\t%s\n", k) | ||
// for _, v := range v.Workspaces { | ||
// fmt.Printf("\t\t\t%s\n", v) | ||
// } | ||
// } | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters