Skip to content

Commit a3dff84

Browse files
committed
quadlet/main: add missing extensions
cmd/quadlet: add common.AutocompleteQuadlets Signed-off-by: flouthoc <[email protected]>
1 parent 11d173f commit a3dff84

File tree

5 files changed

+52
-13
lines changed

5 files changed

+52
-13
lines changed

cmd/podman/common/completion.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,28 @@ func getPods(cmd *cobra.Command, toComplete string, cType completeType, statuses
173173
return suggestions, cobra.ShellCompDirectiveNoFileComp
174174
}
175175

176+
func getQuadlets(cmd *cobra.Command, toComplete string) ([]string, cobra.ShellCompDirective) {
177+
suggestions := []string{}
178+
lsOpts := entities.QuadletListOptions{}
179+
engine, err := setupContainerEngine(cmd)
180+
if err != nil {
181+
cobra.CompErrorln(err.Error())
182+
return nil, cobra.ShellCompDirectiveNoFileComp
183+
}
184+
quadlets, err := engine.QuadletList(registry.Context(), lsOpts)
185+
if err != nil {
186+
cobra.CompErrorln(err.Error())
187+
return nil, cobra.ShellCompDirectiveNoFileComp
188+
}
189+
190+
for _, q := range quadlets {
191+
if strings.HasPrefix(q.Name, toComplete) {
192+
suggestions = append(suggestions, q.Name)
193+
}
194+
}
195+
return suggestions, cobra.ShellCompDirectiveNoFileComp
196+
}
197+
176198
func getVolumes(cmd *cobra.Command, toComplete string) ([]string, cobra.ShellCompDirective) {
177199
suggestions := []string{}
178200
lsOpts := entities.VolumeListOptions{}
@@ -730,6 +752,14 @@ func AutocompleteImages(cmd *cobra.Command, args []string, toComplete string) ([
730752
return getImages(cmd, toComplete)
731753
}
732754

755+
// AutocompleteQuadlets - Autocomplete quadlets.
756+
func AutocompleteQuadlets(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
757+
if !validCurrentCmdLine(cmd, args, toComplete) {
758+
return nil, cobra.ShellCompDirectiveNoFileComp
759+
}
760+
return getQuadlets(cmd, toComplete)
761+
}
762+
733763
// AutocompleteManifestListAndMember - Autocomplete names of manifest lists and digests of items in them.
734764
func AutocompleteManifestListAndMember(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
735765
if !validCurrentCmdLine(cmd, args, toComplete) {

cmd/podman/quadlet/install.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ var (
2525
}
2626
return nil
2727
},
28-
// TODO: Autocomplete valid extensions only
29-
ValidArgsFunction: completion.AutocompleteDefault,
28+
ValidArgsFunction: completion.AutocompleteNone,
3029
Example: `podman quadlet install /path/to/myquadlet.container
3130
podman quadlet install https://github.com/containers/podman/blob/main/test/e2e/quadlet/basic.container
3231
podman quadlet install oci-artifact://my-artifact:latest`,

cmd/podman/quadlet/print.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package quadlet
33
import (
44
"fmt"
55

6+
"github.com/containers/podman/v5/cmd/podman/common"
67
"github.com/containers/podman/v5/cmd/podman/registry"
78
"github.com/spf13/cobra"
89
)
@@ -11,12 +12,12 @@ var (
1112
quadletPrintDescription = `Print the contents of a Quadlet, displaying the file including all comments`
1213

1314
quadletPrintCmd = &cobra.Command{
14-
Use: "print [options] QUADLET",
15-
Short: "Display the contents of a quadlet",
16-
Long: quadletPrintDescription,
17-
RunE: print,
18-
// TODO: Autocomplete
19-
Args: cobra.ExactArgs(1),
15+
Use: "print [options] QUADLET",
16+
Short: "Display the contents of a quadlet",
17+
Long: quadletPrintDescription,
18+
RunE: print,
19+
ValidArgsFunction: common.AutocompleteQuadlets,
20+
Args: cobra.ExactArgs(1),
2021
Example: `podman quadlet print myquadlet.container
2122
podman quadlet print mypod.pod
2223
podman quadlet print myimage.build`,

cmd/podman/quadlet/remove.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66

7+
"github.com/containers/podman/v5/cmd/podman/common"
78
"github.com/containers/podman/v5/cmd/podman/registry"
89
"github.com/containers/podman/v5/pkg/domain/entities"
910
"github.com/sirupsen/logrus"
@@ -14,11 +15,11 @@ var (
1415
quadletRmDescription = `Remove one or more installed Quadlets from the current user`
1516

1617
quadletRmCmd = &cobra.Command{
17-
Use: "rm [options] QUADLET [QUADLET...]",
18-
Short: "Remove Quadlets",
19-
Long: quadletRmDescription,
20-
RunE: rm,
21-
// TODO: Arg validation plus completion
18+
Use: "rm [options] QUADLET [QUADLET...]",
19+
Short: "Remove Quadlets",
20+
Long: quadletRmDescription,
21+
RunE: rm,
22+
ValidArgsFunction: common.AutocompleteQuadlets,
2223
Example: `podman quadlet rm test.container
2324
podman quadlet rm --force mysql.container
2425
podman quadlet rm --all --reload-systemd=false`,

cmd/quadlet/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,14 @@ func generateUnitsInfoMap(units []*parser.UnitFile) map[string]*quadlet.UnitInfo
386386
// Prefill resouceNames for .pod files.
387387
// This is requires for referencing the pod from .container files
388388
resourceName = quadlet.GetPodResourceName(unit)
389+
case strings.HasSuffix(unit.Filename, ".volume"):
390+
serviceName = quadlet.GetVolumeServiceName(unit)
391+
case strings.HasSuffix(unit.Filename, ".kube"):
392+
serviceName = quadlet.GetKubeServiceName(unit)
393+
case strings.HasSuffix(unit.Filename, ".network"):
394+
serviceName = quadlet.GetNetworkServiceName(unit)
395+
case strings.HasSuffix(unit.Filename, ".image"):
396+
serviceName = quadlet.GetImageServiceName(unit)
389397
default:
390398
Logf("Unsupported file type %q", unit.Filename)
391399
continue

0 commit comments

Comments
 (0)