Skip to content

Commit

Permalink
Add WithUser docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhitt committed Nov 27, 2022
1 parent b50135a commit 4b24952
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions command_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 8 additions & 0 deletions command_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 8 additions & 0 deletions command_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 4b24952

Please sign in to comment.