Reverted changes that used bubbletea lib
Fixed some minor issues with backup func added stdout to backup functions added stdout to launchserver functions changed tar execs to add verbos for stdout
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
@@ -13,7 +14,8 @@ func backUp(cmd string, c GoConfig) {
|
||||
t := time.Now()
|
||||
timeStamp := t.Format(time.RFC3339)
|
||||
fullBackupName := fmt.Sprintf("%s/ServerBackup.%s.tgz", c.Config.BackupDir, timeStamp)
|
||||
fullBackup := exec.Command("tar", "-czf", fullBackupName, c.Config.ServDir)
|
||||
fullBackup := exec.Command("tar", "-czvf", fullBackupName, c.Config.ServDir)
|
||||
fullBackup.Stdout = os.Stdout
|
||||
err := fullBackup.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Backup Failed: %s\n", err)
|
||||
@@ -24,7 +26,8 @@ func backUp(cmd string, c GoConfig) {
|
||||
timeStamp := t.Format(time.RFC3339)
|
||||
savesBackupName := fmt.Sprintf("%s/SaveBackup.%s.tgz", c.Config.BackupDir, timeStamp)
|
||||
saveDir := fmt.Sprintf("%s/saves", c.Config.ServDir)
|
||||
savesBackup := exec.Command("tar", "-czf", savesBackupName, saveDir)
|
||||
savesBackup := exec.Command("tar", "-czvf", savesBackupName, saveDir)
|
||||
savesBackup.Stdout = os.Stdout
|
||||
err := savesBackup.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Backup Failed: %s\n", err)
|
||||
|
||||
10
config.yml
10
config.yml
@@ -1,9 +1,9 @@
|
||||
server:
|
||||
serverFolder: "./factorio-headless_linux_2.0.72/factorio"
|
||||
serverFolder: "factorio-headless_linux_2.0.72/factorio"
|
||||
port: 34197
|
||||
worldFile: "./factorio-headless_linux_2.0.72/factorio/Newworlds.zip"
|
||||
serverSettings: "./factorio-headless_linux_2.0.72/factorio/data/server-settings.json"
|
||||
backupDir: "./factorio-headless_linux_2.0.72/backups"
|
||||
serverExec: "./factorio-headless_linux_2.0.72/factorio/bin/x64/factorio"
|
||||
worldFile: "factorio-headless_linux_2.0.72/factorio/Newworlds.zip"
|
||||
serverSettings: "factorio-headless_linux_2.0.72/factorio/data/server-settings.json"
|
||||
backupDir: "factorio-headless_linux_2.0.72/backups"
|
||||
serverExec: "factorio-headless_linux_2.0.72/factorio/bin/x64/factorio"
|
||||
screen: True
|
||||
screenName: "Factorio"
|
||||
BIN
factoryman
BIN
factoryman
Binary file not shown.
26
go.mod
26
go.mod
@@ -5,29 +5,3 @@ go 1.24.0
|
||||
toolchain go1.24.4
|
||||
|
||||
require gopkg.in/yaml.v3 v3.0.1
|
||||
|
||||
require (
|
||||
github.com/atotto/clipboard v0.1.4 // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/charmbracelet/bubbles v0.21.0 // indirect
|
||||
github.com/charmbracelet/bubbletea v1.3.10 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
|
||||
github.com/charmbracelet/harmonica v0.2.0 // indirect
|
||||
github.com/charmbracelet/lipgloss v1.1.0 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.10.1 // indirect
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
|
||||
github.com/charmbracelet/x/term v0.2.1 // indirect
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/muesli/termenv v0.16.0 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/sahilm/fuzzy v0.1.1 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
golang.org/x/sys v0.36.0 // indirect
|
||||
golang.org/x/text v0.3.8 // indirect
|
||||
)
|
||||
|
||||
49
go.sum
49
go.sum
@@ -1,52 +1,3 @@
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
|
||||
github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg=
|
||||
github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
|
||||
github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
|
||||
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
|
||||
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
|
||||
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
||||
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
||||
github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ=
|
||||
github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
|
||||
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
||||
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
||||
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
||||
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
|
||||
github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
|
||||
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
func startStopServer(cmd string, con GoConfig) {
|
||||
@@ -15,17 +14,11 @@ func startStopServer(cmd string, con GoConfig) {
|
||||
if con.Config.UseScreen { // if screen enabled in confing.yml
|
||||
fmt.Println("Starting factorio server in screen session")
|
||||
startScreenCmd := exec.Command("screen", "-dmS", con.Config.ScreenName, "bash", "-c", x, "; exec sh")
|
||||
//startScreenCmd.Stdout = os.Stdout
|
||||
//startScreenCmd.Stderr = os.Stderr
|
||||
startScreenCmd.Stdout = os.Stdout
|
||||
startScreenCmd.Stderr = os.Stderr
|
||||
err := startScreenCmd.Run()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to start server: %s", err)
|
||||
} else {
|
||||
fmt.Printf("Started server on port %d, in screen named %s\n", con.Config.ServPort, con.Config.ScreenName)
|
||||
y := exec.Command("screen", "-ls")
|
||||
y.Stdout = os.Stdout
|
||||
y.Stderr = os.Stderr
|
||||
err = y.Run()
|
||||
}
|
||||
} else {
|
||||
startSrvCmd := exec.Command("bash", "-c", x)
|
||||
@@ -43,12 +36,7 @@ func startStopServer(cmd string, con GoConfig) {
|
||||
if err != nil {
|
||||
log.Fatalf("Command failed: %s, Error: %v", quitServerCmd.Args, err)
|
||||
} else {
|
||||
time.Sleep(10 * time.Second)
|
||||
y := exec.Command("screen", "-ls")
|
||||
y.Stdout = os.Stdout
|
||||
y.Stderr = os.Stderr
|
||||
err = y.Run()
|
||||
fmt.Printf("Server in screen %s stopped\n", con.Config.ScreenName)
|
||||
fmt.Println("Server Stopped")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
main.go
26
main.go
@@ -3,33 +3,15 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
var mmChouice string
|
||||
|
||||
func mainMenu() {
|
||||
if len(os.Args) == 1 {
|
||||
p := tea.NewProgram((initialmmModel()))
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Printf("Error starting TUI: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
var c = readCfg(fmConfig)
|
||||
|
||||
func main() {
|
||||
c := readCfg(fmConfig)
|
||||
if len(os.Args) == 1 {
|
||||
mainMenu()
|
||||
if mmChouice != "" {
|
||||
if mmChouice == "start" {
|
||||
fmt.Println("works: " + mmChouice)
|
||||
}
|
||||
// IM HERE -+-+-+-+-+-+-+-+-+-+-
|
||||
}
|
||||
fmt.Println("Use 'start', 'stop', or 'backup' command")
|
||||
fmt.Println("ex. factoryman start")
|
||||
fmt.Println("To configure edit 'conifg.yml'")
|
||||
} else if len(os.Args) > 1 {
|
||||
switch os.Args[1] {
|
||||
case "start":
|
||||
|
||||
100
model.mm.go
100
model.mm.go
@@ -1,100 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
var (
|
||||
mmStyle = lipgloss.NewStyle().Margin(1, 2)
|
||||
selectStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("10")).Bold(true)
|
||||
unslectStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("8")).Italic(true)
|
||||
quitStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("1")).Faint(true)
|
||||
)
|
||||
|
||||
type mmModel struct {
|
||||
choices []string
|
||||
cursor int
|
||||
selected string
|
||||
}
|
||||
|
||||
func initialmmModel() mmModel {
|
||||
return mmModel{
|
||||
choices: []string{"Start server", "Stop server", "Backup saves", "Backup server files", "Enable/Disable mods"},
|
||||
}
|
||||
}
|
||||
|
||||
func (m mmModel) Init() tea.Cmd { return nil }
|
||||
|
||||
func (m mmModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+C", "q":
|
||||
return m, tea.Quit
|
||||
case "up", "k":
|
||||
if m.cursor > 0 {
|
||||
m.cursor--
|
||||
}
|
||||
case "down", "j":
|
||||
if m.cursor < len(m.choices)-1 {
|
||||
m.cursor++
|
||||
}
|
||||
case "enter":
|
||||
m.selected = m.choices[m.cursor]
|
||||
if m.selected == "Quit" {
|
||||
return m, tea.Quit
|
||||
}
|
||||
case "esc":
|
||||
m.selected = ""
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m mmModel) View() string {
|
||||
s := "Would you like to...\n"
|
||||
for i, choice := range m.choices {
|
||||
s += "\n"
|
||||
if m.cursor == i {
|
||||
s += selectStyle.Render(fmt.Sprintf("◉ [ %s ]", choice))
|
||||
} else {
|
||||
s += unslectStyle.Render(fmt.Sprintf("◯ %s ", choice))
|
||||
}
|
||||
|
||||
}
|
||||
qHint := "Press q to quit."
|
||||
if m.selected != "" {
|
||||
s += "\n"
|
||||
if m.selected == "Start server" {
|
||||
s += selectStyle.Render("\nstarting server")
|
||||
mmChouice = "start"
|
||||
s += quitStyle.Render(fmt.Sprintf("\n%s\n", qHint))
|
||||
}
|
||||
if m.selected == "Stop server" {
|
||||
s += selectStyle.Render("\nStopping server")
|
||||
mmChouice = "stop"
|
||||
s += quitStyle.Render(fmt.Sprintf("\n%s\n", qHint))
|
||||
}
|
||||
if m.selected == "Backup saves" {
|
||||
s += selectStyle.Render("\nBacking up save directory")
|
||||
mmChouice = "saves"
|
||||
s += quitStyle.Render(fmt.Sprintf("\n%s\n", qHint))
|
||||
}
|
||||
if m.selected == "Backup server files" {
|
||||
s += selectStyle.Render("\nBacking up server files")
|
||||
s += quitStyle.Render(fmt.Sprintf("\n%s\n", qHint))
|
||||
}
|
||||
if m.selected == "Enable/Disable mods" {
|
||||
s += selectStyle.Render("\nnot yet implemented")
|
||||
s += quitStyle.Render(fmt.Sprintf("\n%s\n", qHint))
|
||||
}
|
||||
|
||||
} else {
|
||||
s += quitStyle.Render(fmt.Sprintf("\n\n\n%s\n", qHint))
|
||||
|
||||
}
|
||||
return mmStyle.Render(s)
|
||||
}
|
||||
Reference in New Issue
Block a user