Initial Commit
This commit is contained in:
84
cmd/main.go
Normal file
84
cmd/main.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"strings"
|
||||
|
||||
"gogs.bullercodeworks.com/brian/gosyphus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var proc string
|
||||
if len(os.Args) > 1 {
|
||||
// The first argument is the executable that we want to serve
|
||||
proc = os.Args[1]
|
||||
}
|
||||
cwd, err := os.Getwd()
|
||||
wd := cwd
|
||||
wd = requestParam("Working Directory", wd, true)
|
||||
for !checkFileExists(proc) {
|
||||
if len(proc) > 0 {
|
||||
fmt.Println("Couldn't find file: " + proc)
|
||||
}
|
||||
proc = requestParam("Process", proc, true)
|
||||
}
|
||||
if !strings.HasPrefix(proc, "/") {
|
||||
proc = cwd + "/" + proc
|
||||
}
|
||||
var userName string
|
||||
user, err := user.Current()
|
||||
if err == nil {
|
||||
userName = user.Name
|
||||
}
|
||||
userName = requestParam("Username", userName, true)
|
||||
groupName := requestParam("Group Name", userName, true)
|
||||
//desc := requestParam("Description", "", false)
|
||||
outFile := requestParam("Output File", "", true)
|
||||
if !strings.HasSuffix(outFile, ".service") {
|
||||
outFile = outFile + ".service"
|
||||
}
|
||||
// TODO: Request Environment
|
||||
/*
|
||||
environ := os.Environ()
|
||||
for i := range environ {
|
||||
fmt.Println(environ[i])
|
||||
}
|
||||
*/
|
||||
g := gosyphus.NewService(wd, proc, userName, groupName)
|
||||
//g.Describe(desc)
|
||||
g.GenerateFile(outFile)
|
||||
}
|
||||
|
||||
func requestParam(label, def string, req bool) string {
|
||||
var firstRun = true
|
||||
var newVal string
|
||||
for firstRun || (req && len(newVal) == 0) {
|
||||
fmt.Print(label)
|
||||
fmt.Print(" [")
|
||||
outDef := def
|
||||
if len(outDef) == 0 {
|
||||
outDef = "No default"
|
||||
}
|
||||
fmt.Print(outDef)
|
||||
fmt.Print("]: ")
|
||||
fmt.Scanf("%s", &newVal)
|
||||
if len(newVal) == 0 {
|
||||
newVal = def
|
||||
}
|
||||
firstRun = false
|
||||
}
|
||||
return newVal
|
||||
}
|
||||
|
||||
func checkFileExists(fn string) bool {
|
||||
_, err := os.Stat(fn)
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user