From 4b249528d0c0305a57cdaa2299b5d50834c0d54c Mon Sep 17 00:00:00 2001 From: dylanhitt Date: Thu, 24 Nov 2022 13:01:22 -0500 Subject: [PATCH] Add WithUser docs --- command_darwin.go | 8 ++++++++ command_linux.go | 8 ++++++++ command_windows.go | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/command_darwin.go b/command_darwin.go index f039f7b..35e6355 100644 --- a/command_darwin.go +++ b/command_darwin.go @@ -10,6 +10,14 @@ func createBaseCommand(c *Command) *exec.Cmd { return cmd } +// WithUser allows the command to be run as a different +// user. +// +// Example: +// +// cred := syscall.Credential{Uid: 1000, Gid: 1000} +// c := NewCommand("echo hello", cred) +// c.Execute() func WithUser(credential syscall.Credential) func(c *Command) { return func(c *Command) { c.baseCommand.SysProcAttr = &syscall.SysProcAttr{ diff --git a/command_linux.go b/command_linux.go index f039f7b..35e6355 100644 --- a/command_linux.go +++ b/command_linux.go @@ -10,6 +10,14 @@ func createBaseCommand(c *Command) *exec.Cmd { return cmd } +// WithUser allows the command to be run as a different +// user. +// +// Example: +// +// cred := syscall.Credential{Uid: 1000, Gid: 1000} +// c := NewCommand("echo hello", cred) +// c.Execute() func WithUser(credential syscall.Credential) func(c *Command) { return func(c *Command) { c.baseCommand.SysProcAttr = &syscall.SysProcAttr{ diff --git a/command_windows.go b/command_windows.go index fce4a27..45b8c6f 100644 --- a/command_windows.go +++ b/command_windows.go @@ -10,6 +10,14 @@ func createBaseCommand(c *Command) *exec.Cmd { return cmd } +// WithUser allows the command to be run as a different +// user. +// +// Example: +// +// token := syscall.Token(handle) +// c := NewCommand("echo hello", token) +// c.Execute() func WithUser(token syscall.Token) func(c *Command) { return func(c *Command) { c.baseCommand.SysProcAttr = &syscall.SysProcAttr{