Merge pull request #14695 from boaz0/closes_14682
Fix machine list: --format implies --noheading
This commit is contained in:
commit
cc86315455
|
@ -138,7 +138,7 @@ func outputTemplate(cmd *cobra.Command, responses []*ListReporter) error {
|
||||||
switch {
|
switch {
|
||||||
case cmd.Flags().Changed("format"):
|
case cmd.Flags().Changed("format"):
|
||||||
row = cmd.Flag("format").Value.String()
|
row = cmd.Flag("format").Value.String()
|
||||||
listFlag.noHeading = !report.HasTable(row)
|
printHeader = report.HasTable(row)
|
||||||
row = report.NormalizeFormat(row)
|
row = report.NormalizeFormat(row)
|
||||||
default:
|
default:
|
||||||
row = cmd.Flag("format").Value.String()
|
row = cmd.Flag("format").Value.String()
|
||||||
|
|
|
@ -29,7 +29,7 @@ var _ = Describe("podman machine list", func() {
|
||||||
firstList, err := mb.setCmd(list).run()
|
firstList, err := mb.setCmd(list).run()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(firstList).Should(Exit(0))
|
Expect(firstList).Should(Exit(0))
|
||||||
Expect(len(firstList.outputToStringSlice())).To(Equal(1)) // just the header
|
Expect(firstList.outputToStringSlice()).To(HaveLen(1)) // just the header
|
||||||
|
|
||||||
i := new(initMachine)
|
i := new(initMachine)
|
||||||
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
|
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
|
||||||
|
@ -39,7 +39,7 @@ var _ = Describe("podman machine list", func() {
|
||||||
secondList, err := mb.setCmd(list).run()
|
secondList, err := mb.setCmd(list).run()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(secondList).To(Exit(0))
|
Expect(secondList).To(Exit(0))
|
||||||
Expect(len(secondList.outputToStringSlice())).To(Equal(2)) // one machine and the header
|
Expect(secondList.outputToStringSlice()).To(HaveLen(2)) // one machine and the header
|
||||||
})
|
})
|
||||||
|
|
||||||
It("list machines with quiet or noheading", func() {
|
It("list machines with quiet or noheading", func() {
|
||||||
|
@ -51,12 +51,12 @@ var _ = Describe("podman machine list", func() {
|
||||||
firstList, err := mb.setCmd(list.withQuiet()).run()
|
firstList, err := mb.setCmd(list.withQuiet()).run()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(firstList).Should(Exit(0))
|
Expect(firstList).Should(Exit(0))
|
||||||
Expect(len(firstList.outputToStringSlice())).To(Equal(0)) // No header with quiet
|
Expect(firstList.outputToStringSlice()).To(HaveLen(0)) // No header with quiet
|
||||||
|
|
||||||
noheaderSession, err := mb.setCmd(list.withNoHeading()).run() // noheader
|
noheaderSession, err := mb.setCmd(list.withNoHeading()).run() // noheader
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(noheaderSession).Should(Exit(0))
|
Expect(noheaderSession).Should(Exit(0))
|
||||||
Expect(len(noheaderSession.outputToStringSlice())).To(Equal(0))
|
Expect(noheaderSession.outputToStringSlice()).To(HaveLen(0))
|
||||||
|
|
||||||
i := new(initMachine)
|
i := new(initMachine)
|
||||||
session, err := mb.setName(name1).setCmd(i.withImagePath(mb.imagePath)).run()
|
session, err := mb.setName(name1).setCmd(i.withImagePath(mb.imagePath)).run()
|
||||||
|
@ -70,7 +70,7 @@ var _ = Describe("podman machine list", func() {
|
||||||
secondList, err := mb.setCmd(list.withQuiet()).run()
|
secondList, err := mb.setCmd(list.withQuiet()).run()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(secondList).To(Exit(0))
|
Expect(secondList).To(Exit(0))
|
||||||
Expect(len(secondList.outputToStringSlice())).To(Equal(2)) // two machines, no header
|
Expect(secondList.outputToStringSlice()).To(HaveLen(2)) // two machines, no header
|
||||||
|
|
||||||
listNames := secondList.outputToStringSlice()
|
listNames := secondList.outputToStringSlice()
|
||||||
stripAsterisk(listNames)
|
stripAsterisk(listNames)
|
||||||
|
@ -116,10 +116,10 @@ var _ = Describe("podman machine list", func() {
|
||||||
|
|
||||||
// go format
|
// go format
|
||||||
list := new(listMachine)
|
list := new(listMachine)
|
||||||
listSession, err := mb.setCmd(list.withFormat("{{.Name}}").withNoHeading()).run()
|
listSession, err := mb.setCmd(list.withFormat("{{.Name}}")).run()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(listSession).To(Exit(0))
|
Expect(listSession).To(Exit(0))
|
||||||
Expect(len(listSession.outputToStringSlice())).To(Equal(1))
|
Expect(listSession.outputToStringSlice()).To(HaveLen(1))
|
||||||
|
|
||||||
listNames := listSession.outputToStringSlice()
|
listNames := listSession.outputToStringSlice()
|
||||||
stripAsterisk(listNames)
|
stripAsterisk(listNames)
|
||||||
|
@ -135,6 +135,15 @@ var _ = Describe("podman machine list", func() {
|
||||||
var listResponse []*machine.ListReporter
|
var listResponse []*machine.ListReporter
|
||||||
err = jsoniter.Unmarshal(listSession.Bytes(), &listResponse)
|
err = jsoniter.Unmarshal(listSession.Bytes(), &listResponse)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
// table format includes the header
|
||||||
|
list = new(listMachine)
|
||||||
|
listSession3, err3 := mb.setCmd(list.withFormat("table {{.Name}}")).run()
|
||||||
|
Expect(err3).NotTo(HaveOccurred())
|
||||||
|
Expect(listSession3).To(Exit(0))
|
||||||
|
listNames3 := listSession3.outputToStringSlice()
|
||||||
|
Expect(listNames3).To(HaveLen(2))
|
||||||
|
Expect(listNames3).To(ContainSubstring("NAME"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue