Remove persist option from configure commands

This commit is contained in:
Gregory Kurtzer
2021-04-23 21:06:57 -07:00
parent d1bc747cc2
commit 19d4fec376
11 changed files with 42 additions and 51 deletions

View File

@@ -2,7 +2,6 @@ package hosts
import (
"bytes"
"fmt"
"os"
"text/template"
@@ -21,14 +20,13 @@ type TemplateStruct struct {
}
func CobraRunE(cmd *cobra.Command, args []string) error {
return Configure(SetShow)
}
func Configure(show bool) error {
var replace TemplateStruct
if SetShow == false && SetPersist == false {
fmt.Println(cmd.Help())
os.Exit(0)
}
if util.IsFile("/etc/warewulf/hosts.tmpl") == false {
if !util.IsFile("/etc/warewulf/hosts.tmpl") {
wwlog.Printf(wwlog.WARN, "Template not found, not updating host file\n")
return nil
}
@@ -90,7 +88,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
replace.Ipaddr = controller.Ipaddr
replace.Fqdn = controller.Fqdn
if SetShow == false {
if !SetShow {
// only open "/etc/hosts" when intended to write, as 'os.O_TRUNC' will empty the file otherwise.
w, err = os.OpenFile("/etc/hosts", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {

View File

@@ -10,13 +10,11 @@ var (
"Warewulf configuration directory.",
RunE: CobraRunE,
}
SetShow bool
SetPersist bool
SetShow bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)")
baseCmd.PersistentFlags().BoolVar(&SetPersist, "persist", false, "Persist the configuration and initialize the service")
}
// GetRootCommand returns the root cobra.Command for the application.