add quadlet -version flag

I recently wanted to check which version of Quadlet I was using and
found a `-version` flag to be missing.  Since Quadlet and Podman are
bundled together, it seems reasonable to me for them to share the same
version.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2023-04-04 10:04:46 +02:00
parent 7eb78f8a74
commit 243ca7c280
2 changed files with 19 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/containers/podman/v4/pkg/systemd/parser" "github.com/containers/podman/v4/pkg/systemd/parser"
"github.com/containers/podman/v4/pkg/systemd/quadlet" "github.com/containers/podman/v4/pkg/systemd/quadlet"
"github.com/containers/podman/v4/version/rawversion"
) )
// This commandline app is the systemd generator (system and user, // This commandline app is the systemd generator (system and user,
@ -27,6 +28,7 @@ var (
noKmsgFlag bool noKmsgFlag bool
isUserFlag bool // True if run as quadlet-user-generator executable isUserFlag bool // True if run as quadlet-user-generator executable
dryRunFlag bool // True if -dryrun is used dryRunFlag bool // True if -dryrun is used
versionFlag bool // True if -version is used
) )
var ( var (
@ -298,6 +300,11 @@ func main() {
flag.Parse() flag.Parse()
if versionFlag {
fmt.Printf("%s\n", rawversion.RawVersion)
return
}
if verboseFlag || dryRunFlag { if verboseFlag || dryRunFlag {
enableDebug() enableDebug()
} }
@ -389,5 +396,6 @@ func init() {
flag.BoolVar(&verboseFlag, "v", false, "Print debug information") flag.BoolVar(&verboseFlag, "v", false, "Print debug information")
flag.BoolVar(&noKmsgFlag, "no-kmsg-log", false, "Don't log to kmsg") flag.BoolVar(&noKmsgFlag, "no-kmsg-log", false, "Don't log to kmsg")
flag.BoolVar(&isUserFlag, "user", false, "Run as systemd user") flag.BoolVar(&isUserFlag, "user", false, "Run as systemd user")
flag.BoolVar(&dryRunFlag, "dryrun", false, "run in dryrun mode printing debug information") flag.BoolVar(&dryRunFlag, "dryrun", false, "Run in dryrun mode printing debug information")
flag.BoolVar(&versionFlag, "version", false, "Print version information and exit")
} }

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"github.com/containers/podman/v4/pkg/systemd/parser" "github.com/containers/podman/v4/pkg/systemd/parser"
"github.com/containers/podman/v4/version"
"github.com/mattn/go-shellwords" "github.com/mattn/go-shellwords"
. "github.com/containers/podman/v4/test/utils" . "github.com/containers/podman/v4/test/utils"
@ -426,6 +427,15 @@ var _ = Describe("quadlet system generator", func() {
}) })
Describe("quadlet -version", func() {
It("Should print correct version", func() {
session := podmanTest.Quadlet([]string{"-version"}, "/something")
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(Equal(version.Version.String()))
})
})
Describe("Running quadlet dryrun tests", func() { Describe("Running quadlet dryrun tests", func() {
It("Should exit with an error because of no files are found to parse", func() { It("Should exit with an error because of no files are found to parse", func() {
fileName := "basic.kube" fileName := "basic.kube"