service-tools/main.go

41 lines
766 B
Go
Raw Normal View History

2018-03-09 22:23:05 +01:00
package main
import (
2018-03-10 22:29:11 +01:00
"bufio"
"errors"
"fmt"
2018-03-09 22:23:05 +01:00
"os"
2018-03-10 22:29:11 +01:00
"strings"
2018-03-09 22:23:05 +01:00
"github.com/spf13/cobra"
)
var (
RootCmd = &cobra.Command{
Use: "service-generator",
Short: "service-generator creates systemd Unit files",
Long: "service-generator is a convenient little tool to create systemd Unit files",
SilenceErrors: false,
SilenceUsage: true,
}
)
2018-03-10 22:29:11 +01:00
func readString(prompt string, required bool) (string, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("%s: ", prompt)
text, err := reader.ReadString('\n')
text = strings.TrimSpace(text)
if required && len(text) == 0 {
return "", errors.New("Required string is empty")
}
return text, err
}
2018-03-09 22:23:05 +01:00
func main() {
if err := RootCmd.Execute(); err != nil {
os.Exit(-1)
}
}