-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
actions: apt: Abstract apt commands into separate wrapper
The apt commands will also be used by the install-dpkg wrapper, prepare for this by abstracting the generic apt commands into a wrapper class. Also create a wrapper base class to be able to abstract common action commands into generic functions. Signed-off-by: Christopher Obbard <[email protected]>
- Loading branch information
Showing
3 changed files
with
95 additions
and
35 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
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,49 @@ | ||
/* Abstracts the apt command. */ | ||
package wrapper | ||
|
||
import ( | ||
"github.com/go-debos/debos" | ||
) | ||
|
||
type AptCommand struct { | ||
Wrapper | ||
} | ||
|
||
func NewAptCommand(context debos.DebosContext, label string) AptCommand { | ||
command := "apt-get" | ||
|
||
apt := AptCommand{ | ||
Wrapper: NewCommandWrapper(context, command, label), | ||
} | ||
|
||
apt.AddEnv("DEBIAN_FRONTEND=noninteractive") | ||
|
||
/* Don't show progress update percentages */ | ||
apt.AppendGlobalArguments("-o=quiet::NoUpdate=1") | ||
|
||
return apt | ||
} | ||
|
||
func (apt AptCommand) Clean() error { | ||
return apt.Run("clean") | ||
} | ||
|
||
func (apt AptCommand) Install(packages []string, recommends bool, unauthenticated bool) error { | ||
arguments := []string{"install", "--yes"} | ||
|
||
if !recommends { | ||
arguments = append(arguments, "--no-install-recommends") | ||
} | ||
|
||
if unauthenticated { | ||
arguments = append(arguments, "--allow-unauthenticated") | ||
} | ||
|
||
arguments = append(arguments, packages...) | ||
|
||
return apt.Run(arguments...) | ||
} | ||
|
||
func (apt AptCommand) Update() error { | ||
return apt.Run("update") | ||
} |
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,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.DebosContext, 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...) | ||
} |