command

package module
v1.171.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved. * SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsShellForm

func AsShellForm(cmd string, args ...string) string

AsShellForm returns a command in its shell form.

Types

type CommandAsDifferentUser

type CommandAsDifferentUser struct {
	// contains filtered or unexported fields
}

CommandAsDifferentUser helps to redefine commands so that they are run as a different user or with more privileges.

func Elevate

func Elevate() *CommandAsDifferentUser

Elevate will call commands with [elevate](https://learn.microsoft.com/en-us/previous-versions/technet-magazine/cc162321(v=msdn.10)) assuming the tool is installed on the platform. (For WINDOWS only)

func Gosu

func Gosu(username string) *CommandAsDifferentUser

Gosu is similar to NewCommandInContainerAs.

func Me

Me will run the commands without switching user. It is a no operation wrapper.

func NewCommandAsDifferentUser

func NewCommandAsDifferentUser(switchUserCmd ...string) *CommandAsDifferentUser

NewCommandAsDifferentUser defines a command wrapper which helps to redefine commands so that they are run as a different user. e.g.

  • switchUserCmd="sudo" to run commands as `root`
  • switchUserCmd="su", "tom" if `tom` has enough privileges to run the command
  • switchUserCmd="gosu", "tom" if `tom` has enough privileges to run the command in a container and `gosu` is installed

func NewCommandAsRoot

func NewCommandAsRoot() *CommandAsDifferentUser

NewCommandAsRoot will create a command translator which will run command with `sudo` (for Unix Only)

func NewCommandInContainerAs

func NewCommandInContainerAs(username string) *CommandAsDifferentUser

NewCommandInContainerAs will redefine commands to be run in containers as `username`. It will expect [gosu](https://github.com/tianon/gosu) to be installed and the user to have been defined.

func RunAs

func RunAs(username string) *CommandAsDifferentUser

RunAs will run commands as the user username using [runas](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/cc771525%28v=ws.11%29) (For WINDOWS only)

func ShellRunAs

func ShellRunAs() *CommandAsDifferentUser

ShellRunAs will call commands with [shellrunas](https://learn.microsoft.com/en-gb/sysinternals/downloads/shellrunas) assuming [SysInternals](https://docs.microsoft.com/en-gb/sysinternals/downloads/sysinternals-suite) is installed on the platform. (For WINDOWS only)

func Su

func Su(username string) *CommandAsDifferentUser

Su will run commands as the user username using [su](https://www.unix.com/man-page/posix/1/su/) (for Unix Only)

func Sudo

func Sudo() *CommandAsDifferentUser

Sudo will call commands with `sudo`. Similar to NewCommandAsRoot (for Unix Only)

func (*CommandAsDifferentUser) Prepend

Prepend prepends a command translator to this command translator This can be used to run command as a separate user and with higher privileges e.g. `sudo`. It returns this for use in fluent expressions e.g. Gosu(...).Prepend(Sudo()).RedefineInShellForm(...)

func (*CommandAsDifferentUser) Redefine

func (c *CommandAsDifferentUser) Redefine(cmd string, args ...string) (cmdName string, cmdArgs []string)

Redefine redefines a command so that it will be run as a different user.

func (*CommandAsDifferentUser) RedefineCommand

func (c *CommandAsDifferentUser) RedefineCommand(args ...string) (cmdName string, cmdArgs []string)

RedefineCommand is the same as Redefine but with no separation between the command and its arguments (like the command in Docker)

func (*CommandAsDifferentUser) RedefineInShellForm

func (c *CommandAsDifferentUser) RedefineInShellForm(cmd string, args ...string) string

RedefineInShellForm returns the new command defined in shell form.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL