-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
956bc59
commit 0c0e7a2
Showing
7 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package console | ||
|
||
import "io" | ||
|
||
func New(exePath string, args []string, stdout io.Writer) *Console { | ||
p := NewParser() | ||
|
||
return &Console{ | ||
commandLine: exePath, | ||
stdout: stdout, | ||
args: args, | ||
Parser: p, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//go:build unix | ||
|
||
package console | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os/exec" | ||
) | ||
|
||
type Console struct { | ||
stdout io.Writer // stdout is the writer where the output will be written to. | ||
commandLine string // commandLine is the command that will be executed. | ||
proc *exec.Cmd | ||
exitCode uint32 | ||
args []string | ||
Parser *Parser | ||
} | ||
|
||
// Run executes the command in steamcmd and returns the exit code. Exit code does not need to be 0 to return no errors (error is for executing the pseudoconsole) | ||
func (c *Console) Run() (uint32, error) { | ||
var err error | ||
|
||
if c.commandLine == "" { | ||
_, err := exec.LookPath(c.commandLine) | ||
if err != nil { | ||
return 1, fmt.Errorf("Steamcmd not found: %v\n", err) | ||
} | ||
} | ||
|
||
var a []string | ||
a = append(a, c.commandLine) | ||
a = append(a, c.args...) | ||
|
||
c.proc = exec.Command("sh", a...) | ||
if err != nil { | ||
return 1, err | ||
} | ||
|
||
d := &duplicateWriter{ | ||
writer1: c.Parser, | ||
writer2: c.stdout, | ||
} | ||
|
||
c.proc.Stdout = d | ||
c.proc.Stderr = d | ||
|
||
err = c.proc.Run() | ||
if err != nil { | ||
if exitErr, ok := err.(*exec.ExitError); ok { | ||
c.exitCode = uint32(exitErr.ExitCode()) | ||
} else { | ||
return 1, err | ||
} | ||
} | ||
c.exitCode = uint32(c.proc.ProcessState.ExitCode()) | ||
|
||
return c.exitCode, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/jensvandewiel/gosteamcmd" | ||
"github.com/jensvandewiel/gosteamcmd/console" | ||
"os" | ||
) | ||
|
||
func main() { | ||
//this code follows the steps of: https://www.rustafied.com/how-to-host-your-own-rust-server | ||
|
||
prompts := []*gosteamcmd.Prompt{ | ||
gosteamcmd.ForceInstallDir("/home/jens/rustserver"), | ||
gosteamcmd.Login("", ""), | ||
gosteamcmd.AppUpdate(258550, "", true), | ||
} | ||
|
||
cmd := gosteamcmd.New(os.Stdout, prompts, "/mnt/MyProjects/gosteamcmd/steamcmd.sh") | ||
|
||
cmd.Console.Parser.OnInformationReceived = func(action console.Action, progress float64, currentWritten, total uint64) { | ||
println("") | ||
} | ||
cmd.Console.Parser.OnAppInstalled = func(app uint32) { | ||
println("App installed: ", app, " Yay!") | ||
} | ||
|
||
_, err := cmd.Run() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
github.com/UserExistsError/conpty v0.1.1 h1:cHDsU/XeoeDAQmVvCTV53SrXLG39YJ4++Pp3iAi1gXE= | ||
github.com/UserExistsError/conpty v0.1.1/go.mod h1:PDglKIkX3O/2xVk0MV9a6bCWxRmPVfxqZoTG/5sSd9I= | ||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= | ||
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= | ||
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= | ||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= | ||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= | ||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters