Skip to content

Commit ed537d5

Browse files
authored
feat: Add path flag to ArgoCD CLI app list (argoproj#24834)
Signed-off-by: Omar Nasser <omarnasserjr@gmail.com>
1 parent afaf16b commit ed537d5

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

cmd/argocd/commands/app.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,7 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
17941794
repo string
17951795
appNamespace string
17961796
cluster string
1797+
path string
17971798
)
17981799
command := &cobra.Command{
17991800
Use: "list",
@@ -1829,6 +1830,9 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
18291830
if cluster != "" {
18301831
appList = argo.FilterByCluster(appList, cluster)
18311832
}
1833+
if path != "" {
1834+
appList = argo.FilterByPath(appList, path)
1835+
}
18321836

18331837
switch output {
18341838
case "yaml", "json":
@@ -1849,6 +1853,7 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
18491853
command.Flags().StringVarP(&repo, "repo", "r", "", "List apps by source repo URL")
18501854
command.Flags().StringVarP(&appNamespace, "app-namespace", "N", "", "Only list applications in namespace")
18511855
command.Flags().StringVarP(&cluster, "cluster", "c", "", "List apps by cluster name or url")
1856+
command.Flags().StringVarP(&path, "path", "P", "", "List apps by path")
18521857
return command
18531858
}
18541859

docs/user-guide/commands/argocd_app_list.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.work.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYr
188188
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
189189
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
190190
github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI=
191+
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
191192
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
192193
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
193194
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
@@ -215,6 +216,7 @@ go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
215216
go.opentelemetry.io/contrib/detectors/gcp v1.36.0/go.mod h1:IbBN8uAIIx734PTonTPxAxnjc2pQTxWNkwfstZ+6H2k=
216217
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.44.0/go.mod h1:uq8DrRaen3suIWTpdR/JNHCGpurSvMv9D5Nr5CU5TXc=
217218
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds=
219+
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
218220
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
219221
google.golang.org/genproto/googleapis/bytestream v0.0.0-20250219182151-9fdb1cabc7b2/go.mod h1:35wIojE/F1ptq1nfNDNjtowabHoMSA2qQs7+smpCO5s=
220222
gopkg.in/go-jose/go-jose.v2 v2.6.3/go.mod h1:zzZDPkNNw/c9IE7Z9jr11mBZQhKQTMzoEEIoEdZlFBI=

util/argo/argo.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,20 @@ func FilterByRepoP(apps []*argoappv1.Application, repo string) []*argoappv1.Appl
180180
return items
181181
}
182182

183+
// FilterByPath returns an application
184+
func FilterByPath(apps []argoappv1.Application, path string) []argoappv1.Application {
185+
if path == "" {
186+
return apps
187+
}
188+
items := make([]argoappv1.Application, 0)
189+
for i := 0; i < len(apps); i++ {
190+
if apps[i].Spec.GetSource().Path == path {
191+
items = append(items, apps[i])
192+
}
193+
}
194+
return items
195+
}
196+
183197
// FilterByCluster returns an application
184198
func FilterByCluster(apps []argoappv1.Application, cluster string) []argoappv1.Application {
185199
if cluster == "" {

util/argo/argo_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,40 @@ func TestFilterByRepoP(t *testing.T) {
624624
})
625625
}
626626

627+
func TestFilterByPath(t *testing.T) {
628+
apps := []argoappv1.Application{
629+
{
630+
Spec: argoappv1.ApplicationSpec{
631+
Source: &argoappv1.ApplicationSource{
632+
Path: "example/app/foo",
633+
},
634+
},
635+
},
636+
{
637+
Spec: argoappv1.ApplicationSpec{
638+
Source: &argoappv1.ApplicationSource{
639+
Path: "example/app/existent",
640+
},
641+
},
642+
},
643+
}
644+
645+
t.Run("Empty filter", func(t *testing.T) {
646+
res := FilterByPath(apps, "")
647+
assert.Len(t, res, 2)
648+
})
649+
650+
t.Run("Found one match", func(t *testing.T) {
651+
res := FilterByPath(apps, "example/app/foo")
652+
assert.Len(t, res, 1)
653+
})
654+
655+
t.Run("No match found", func(t *testing.T) {
656+
res := FilterByPath(apps, "example/app/non-existent")
657+
assert.Empty(t, res)
658+
})
659+
}
660+
627661
func TestValidatePermissions(t *testing.T) {
628662
t.Run("Empty Repo URL result in condition", func(t *testing.T) {
629663
spec := argoappv1.ApplicationSpec{

0 commit comments

Comments
 (0)