Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Jun 26, 2019
1 parent fbfeed3 commit c12d995
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
1 change: 0 additions & 1 deletion cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

func GetConfig(cmd *cobra.Command, args []string) *types.Config {

configs, err := cmd.Flags().GetStringSlice("config")
if err != nil {
log.Fatalf("%s", err)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
func init() {
log.SetOutput(os.Stderr)
}

func main() {
var root = &cobra.Command{
Use: "konfigadm",
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud-init/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ type PowerState struct {
// 0: condition met
// 1: condition not met
// other exit codes will result in 'not met', but are reserved for future use.
Condition bool `yaml:"condition,omitempty"`
Condition string `yaml:"condition,omitempty"`
}

type MAASDatasource struct {
Expand Down
29 changes: 26 additions & 3 deletions pkg/types/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ func NewCommand(cmd string) Commands {
}
}

func (c *Commands) Add(commands ...string) Commands {
func (c *Commands) AddAll(cmd ...Command) *Commands {
if c.commands == nil {
c.commands = &[]Command{}
}
commandsSlice := *c.commands
commandsSlice = append(commandsSlice, cmd...)
c.commands = &commandsSlice
return c
}

func (c *Commands) Add(commands ...string) *Commands {
if c.commands == nil {
c.commands = &[]Command{}
}
Expand All @@ -34,10 +44,10 @@ func (c *Commands) Add(commands ...string) Commands {
commandsSlice = append(commandsSlice, Command{Cmd: command})
}
c.commands = &commandsSlice
return *c
return c
}

func (c Commands) AddDependency(commands ...string) Commands {
func (c *Commands) AddDependency(commands ...string) *Commands {
if c.dependencies == nil {
c.dependencies = &[]Command{}
}
Expand All @@ -49,6 +59,19 @@ func (c Commands) AddDependency(commands ...string) Commands {
return c
}

func (c Commands) GetCommands() []Command {
if c.dependencies == nil && c.commands == nil {
return []Command{}
}
if c.dependencies == nil {
return *c.commands
}
if c.commands == nil {
return *c.dependencies
}
return append(*c.dependencies, *c.commands...)
}

func (c1 *Commands) Append(c2 Commands) *Commands {
var cmdSlice []Command
var depSlice []Command
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (sys *Config) ToCloudInit() cloudinit.CloudInit {

//ToScript returns a bash script of all the commands that can be run directly
func ToScript(commands []Command) string {
script := "#!/bin/bash\n"
script := "#!/bin/bash\nset -o verbose\n"
for _, command := range commands {
script += command.Cmd + "\n"
}
Expand Down

0 comments on commit c12d995

Please sign in to comment.