Skip to content

Commit

Permalink
cmd/create, pkg/utils: Simplify hint after creating a container
Browse files Browse the repository at this point in the history
A subsequent commit will add support for configuration files, which can
override the default toolbox image. Since this override affects all
commands, it effectively ends up adding a fourth option to the 'enter'
command, other than the existing options to change the distribution,
release and container. This makes it a lot more difficult to reason
when only 'toolbox enter --release N' is enough to enter the created
container.

containers#828
containers#851
  • Loading branch information
debarshiray committed Jul 23, 2021
1 parent 6a37695 commit 5824f0a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func createContainer(container, image, release string, showCommandToEnter bool)
panic("release not specified")
}

enterCommand := getEnterCommand(container, release)
enterCommand := getEnterCommand(container)

logrus.Debugf("Checking if container %s already exists", container)

Expand Down Expand Up @@ -503,15 +503,12 @@ func getDBusSystemSocket() (string, error) {
return pathEvaled, nil
}

func getEnterCommand(container, release string) string {
func getEnterCommand(container string) string {
var enterCommand string
containerNamePrefixDefaultWithRelease := utils.ContainerNamePrefixDefault + "-" + release

switch container {
case utils.ContainerNameDefault:
enterCommand = fmt.Sprintf("%s enter", executableBase)
case containerNamePrefixDefaultWithRelease:
enterCommand = fmt.Sprintf("%s enter --release %s", executableBase, release)
default:
enterCommand = fmt.Sprintf("%s enter %s", executableBase, container)
}
Expand Down
9 changes: 5 additions & 4 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const (
)

var (
containerNamePrefixDefault = "fedora-toolbox"

distroDefault = "fedora"

preservedEnvironmentVariables = []string{
Expand Down Expand Up @@ -112,8 +114,7 @@ var (
)

var (
ContainerNameDefault string
ContainerNamePrefixDefault = "fedora-toolbox"
ContainerNameDefault string
)

func init() {
Expand All @@ -124,14 +125,14 @@ func init() {
if distroObj, supportedDistro := supportedDistros[hostID]; supportedDistro {
release, err := GetHostVersionID()
if err == nil {
ContainerNamePrefixDefault = distroObj.ContainerNamePrefix
containerNamePrefixDefault = distroObj.ContainerNamePrefix
distroDefault = hostID
releaseDefault = release
}
}
}

ContainerNameDefault = ContainerNamePrefixDefault + "-" + releaseDefault
ContainerNameDefault = containerNamePrefixDefault + "-" + releaseDefault
}

func AskForConfirmation(prompt string) bool {
Expand Down
2 changes: 1 addition & 1 deletion test/system/101-create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ teardown() {

assert_success
assert_output --partial "Created container: fedora-toolbox-32"
assert_output --partial "Enter with: toolbox enter --release 32"
assert_output --partial "Enter with: toolbox enter fedora-toolbox-32"

# Make sure the container has actually been created
run podman ps -a
Expand Down

0 comments on commit 5824f0a

Please sign in to comment.