logman/generate.go
Wyatt J. Miller dbde9b3cab Finished generate.go, modified main.go
I completed the process of generating the configuration file for
idiots like me who like to delete configuration files. Don't
worry, it's only by accident ;)

I also modified main.go so that the generating process actually
becomes useful.

What happens is that the program checks if the
configuration file exists (which will have to change to become
more modular as I have it set to look in the current directory
you're in) and if it doesn't, it goes ahead creates it and inputs
some random junk in there that is actually supposed to help with
your own configuration.
2019-09-29 13:38:58 -04:00

62 lines
1.2 KiB
Go

package main
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
// this file is for generating the config if it doesn't exist, mainly for the idiots like me :)
// this is not really a priority right now so it sitting in the backburner as you read this
// signed Wyatt J. Miller, the awesome guy who doesn't generate configs *thumbs up*
var config string = "config.yaml"
func doesConfigExist() bool {
_, err := os.Stat(config)
if err != nil {
return false
}
return true
}
func createTemplateConfig(result bool) {
if result == false {
os.Create(config)
} else {
fmt.Println("Configuration file already created")
}
}
func writeTemplateConfig(filename string) {
hosts := make([]string, 1)
logs := make([]string, 1)
config := Configuration{
"jbob",
"jbobisawesome",
22,
hosts,
logs,
}
data, err := yaml.Marshal(&config)
fmt.Printf(string(data))
_ = ioutil.WriteFile(filename, data, 0600)
if err != nil {
fmt.Errorf("Couldn't create the configuration file", err)
}
fmt.Println("Template for logman's configuration complete!")
fmt.Println("")
fmt.Println("Fill in the necessary credentials you need. If")
fmt.Println("you need assitance, check out the wiki for more.")
os.Exit(0)
}