File: wrapper.go

package info (click to toggle)
debos 1.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 636 kB
  • sloc: sh: 105; makefile: 17
file content (41 lines) | stat: -rw-r--r-- 875 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Base class to abstract commonly used commands. */
package wrapper

import (
	"github.com/go-debos/debos"
)

type Wrapper struct {
	debos.Command
	command    string
	globalArgs []string
	label      string
}

func NewCommandWrapper(context debos.Context, command string, label string) Wrapper {
	return Wrapper{
		Command: debos.NewChrootCommandForContext(context),
		command: command,
		label:   label,
	}
}

func (cmd *Wrapper) SetCommand(command string) {
	cmd.command = command
}

func (cmd *Wrapper) AppendGlobalArguments(args string) {
	cmd.globalArgs = append(cmd.globalArgs, args)
}

func (cmd *Wrapper) SetLabel(label string) {
	cmd.label = label
}

func (cmd Wrapper) Run(additionalArgs ...string) error {
	args := []string{cmd.command}
	args = append(args, cmd.globalArgs...)
	args = append(args, additionalArgs...)

	return cmd.Command.Run(cmd.label, args...)
}