Skip to content

Commit

Permalink
Merge pull request #125 from kazubu/feature/preconf
Browse files Browse the repository at this point in the history
feature: preconf
  • Loading branch information
slankdev authored Jun 30, 2024
2 parents 23b05fa + d6c50f9 commit 6cfe448
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions command_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ func CmdConf(c *cli.Context) error {
nodeinfo[node.Name] = node.Type
}

if len(tnconfig.PreConf) != 0 {
for _, preConf := range tnconfig.PreConf {
preConfCmds := shell.ExecCmd(preConf.Cmds)
utils.PrintCmds(os.Stdout, preConfCmds, verbose)
}
}

for _, nodeConfig := range tnconfig.NodeConfigs {
execConfCmds := nodeConfig.ExecConf(nodeinfo[nodeConfig.Name])
for _, execConfCmd := range execConfCmds {
Expand Down
3 changes: 3 additions & 0 deletions configs/spec_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ precmd:
- cmds:
- cmd: ""
preinit:
- cmds:
- cmd: ""
preconf:
- cmds:
- cmd: ""
postinit:
Expand Down
14 changes: 14 additions & 0 deletions internal/pkg/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var log = l.New()
type Tn struct {
PreCmd []PreCmd `yaml:"precmd"`
PreInit []PreInit `yaml:"preinit"`
PreConf []PreConf `yaml:"preconf"`
PostInit []PostInit `yaml:"postinit"`
PostFini []PostFini `yaml:"postfini"`
Nodes []Node `yaml:"nodes" mapstructure:"nodes"`
Expand All @@ -38,6 +39,11 @@ type PreInit struct {
Cmds []Cmd `yaml:"cmds" mapstructure:"cmds"`
}

// PreConf
type PreConf struct {
Cmds []Cmd `yaml:"cmds" mapstructure:"cmds"`
}

// PostInit
type PostInit struct {
Cmds []Cmd `yaml:"cmds" mapstructure:"cmds"`
Expand Down Expand Up @@ -232,6 +238,13 @@ func GenerateFile() (genContent string, err error) {
},
},
}
preconf := PreConf{
Cmds: []Cmd{
Cmd{
Cmd: "",
},
},
}
postinit := PostInit{
Cmds: []Cmd{
Cmd{
Expand Down Expand Up @@ -341,6 +354,7 @@ func GenerateFile() (genContent string, err error) {
tnconfig := &Tn{
PreCmd: []PreCmd{precmd},
PreInit: []PreInit{preinit},
PreConf: []PreConf{preconf},
PostInit: []PostInit{postinit},
PostFini: []PostFini{postfini},
Nodes: []Node{nodes},
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func TestTn_Exec(t *testing.T) {
type fields struct {
PreCmd []PreCmd
PreInit []PreInit
PreConf []PreConf
PostInit []PostInit
PostFini []PostFini
Nodes []Node
Expand All @@ -253,6 +254,7 @@ func TestTn_Exec(t *testing.T) {
tnconfig := &Tn{
PreCmd: tt.fields.PreCmd,
PreInit: tt.fields.PreInit,
PreConf: tt.fields.PreConf,
PostInit: tt.fields.PostInit,
PostFini: tt.fields.PostFini,
Nodes: tt.fields.Nodes,
Expand Down

0 comments on commit 6cfe448

Please sign in to comment.