From 5824f0adcbb3e7e184a6cec979f4d2253ac083ff Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 23 Jul 2021 01:22:50 +0200 Subject: [PATCH] cmd/create, pkg/utils: Simplify hint after creating a container 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. https://github.com/containers/toolbox/pull/828 https://github.com/containers/toolbox/pull/851 --- src/cmd/create.go | 7 ++----- src/pkg/utils/utils.go | 9 +++++---- test/system/101-create.bats | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/cmd/create.go b/src/cmd/create.go index 87c7217..42cd0de 100644 --- a/src/cmd/create.go +++ b/src/cmd/create.go @@ -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) @@ -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) } diff --git a/src/pkg/utils/utils.go b/src/pkg/utils/utils.go index fb3d628..6baf06a 100644 --- a/src/pkg/utils/utils.go +++ b/src/pkg/utils/utils.go @@ -61,6 +61,8 @@ const ( ) var ( + containerNamePrefixDefault = "fedora-toolbox" + distroDefault = "fedora" preservedEnvironmentVariables = []string{ @@ -112,8 +114,7 @@ var ( ) var ( - ContainerNameDefault string - ContainerNamePrefixDefault = "fedora-toolbox" + ContainerNameDefault string ) func init() { @@ -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 { diff --git a/test/system/101-create.bats b/test/system/101-create.bats index dfb4d89..3cc3eaf 100644 --- a/test/system/101-create.bats +++ b/test/system/101-create.bats @@ -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