Skip to content

Commit acb15e2

Browse files
akoclaude
andcommitted
Add SHOW IMAGE COLLECTION command and example script
New command: SHOW IMAGE COLLECTION [IN Module] lists all image collections with their export level and image count. New example script: 17-image-collection-examples.mdl demonstrates CREATE, SHOW, DESCRIBE, and DROP IMAGE COLLECTION. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 65e39a5 commit acb15e2

8 files changed

Lines changed: 2453 additions & 2194 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
-- ============================================================================
2+
-- Image Collection Examples
3+
-- ============================================================================
4+
--
5+
-- This file demonstrates the MDL syntax for managing image collections.
6+
-- Image collections are Mendix's way of bundling images (icons, logos)
7+
-- within a module.
8+
--
9+
-- Features demonstrated:
10+
-- - CREATE IMAGE COLLECTION (empty)
11+
-- - CREATE IMAGE COLLECTION with EXPORT LEVEL and COMMENT
12+
-- - SHOW IMAGE COLLECTION [IN Module]
13+
-- - DESCRIBE IMAGE COLLECTION
14+
-- - DROP IMAGE COLLECTION
15+
--
16+
-- ============================================================================
17+
18+
CREATE MODULE ImgTest;
19+
20+
-- MARK: Create
21+
22+
-- ============================================================================
23+
-- LEVEL 1: Basic Image Collection
24+
-- ============================================================================
25+
26+
/**
27+
* Level 1.1: Create an empty image collection
28+
*
29+
* The simplest image collection — just a name.
30+
* Images can be added later via Studio Pro.
31+
*/
32+
CREATE IMAGE COLLECTION ImgTest.AppIcons;
33+
/
34+
35+
/**
36+
* Level 1.2: Create with export level
37+
*
38+
* EXPORT LEVEL controls visibility:
39+
* 'Hidden' (default) - internal to the module
40+
* 'Public' - accessible from other modules
41+
*/
42+
CREATE IMAGE COLLECTION ImgTest.SharedIcons EXPORT LEVEL 'Public';
43+
/
44+
45+
/**
46+
* Level 1.3: Create with comment
47+
*
48+
* COMMENT documents the purpose of the collection.
49+
*/
50+
CREATE IMAGE COLLECTION ImgTest.StatusIcons COMMENT 'Icons for order and task status indicators';
51+
/
52+
53+
/**
54+
* Level 1.4: Create with both export level and comment
55+
*/
56+
CREATE IMAGE COLLECTION ImgTest.BrandAssets
57+
EXPORT LEVEL 'Public'
58+
COMMENT 'Company branding assets: logos, favicons, and splash screens';
59+
/
60+
61+
-- MARK: Show
62+
63+
-- ============================================================================
64+
-- LEVEL 2: List Image Collections
65+
-- ============================================================================
66+
67+
-- Show all image collections across all modules
68+
SHOW IMAGE COLLECTION;
69+
/
70+
71+
-- Show image collections in a specific module
72+
SHOW IMAGE COLLECTION IN ImgTest;
73+
/
74+
75+
-- MARK: Describe
76+
77+
-- ============================================================================
78+
-- LEVEL 3: Describe Image Collection
79+
-- ============================================================================
80+
81+
-- Describe shows the full MDL definition including any embedded images
82+
DESCRIBE IMAGE COLLECTION ImgTest.AppIcons;
83+
DESCRIBE IMAGE COLLECTION ImgTest.SharedIcons;
84+
DESCRIBE IMAGE COLLECTION ImgTest.BrandAssets;
85+
86+
-- MARK: Drop
87+
88+
-- ============================================================================
89+
-- LEVEL 4: Drop Image Collection
90+
-- ============================================================================
91+
92+
/**
93+
* Level 4.1: Drop an image collection
94+
*
95+
* Removes the collection and all its embedded images.
96+
*/
97+
DROP IMAGE COLLECTION ImgTest.StatusIcons;
98+
/
99+
100+
-- Verify it's gone
101+
SHOW IMAGE COLLECTION IN ImgTest;
102+
/
103+
104+
-- ============================================================================
105+
-- Summary
106+
-- ============================================================================
107+
--
108+
-- This file demonstrates:
109+
--
110+
-- ✅ CREATE IMAGE COLLECTION Module.Name
111+
-- ✅ CREATE IMAGE COLLECTION with EXPORT LEVEL 'Public'|'Hidden'
112+
-- ✅ CREATE IMAGE COLLECTION with COMMENT 'description'
113+
-- ✅ SHOW IMAGE COLLECTION [IN Module] — list all collections
114+
-- ✅ DESCRIBE IMAGE COLLECTION Module.Name — show full definition
115+
-- ✅ DROP IMAGE COLLECTION Module.Name — remove collection
116+
--
117+
-- ============================================================================

mdl/ast/ast_query.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const (
7474
ShowSettings // SHOW SETTINGS
7575
ShowFragments // SHOW FRAGMENTS
7676
ShowDatabaseConnections // SHOW DATABASE CONNECTIONS [IN module]
77+
ShowImageCollections // SHOW IMAGE COLLECTIONS [IN module]
7778
)
7879

7980
// String returns the human-readable name of the show object type.
@@ -169,6 +170,8 @@ func (t ShowObjectType) String() string {
169170
return "FRAGMENTS"
170171
case ShowDatabaseConnections:
171172
return "DATABASE CONNECTIONS"
173+
case ShowImageCollections:
174+
return "IMAGE COLLECTIONS"
172175
default:
173176
return "UNKNOWN"
174177
}

mdl/executor/cmd_imagecollections.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"strings"
1011

1112
"github.com/mendixlabs/mxcli/mdl/ast"
1213
"github.com/mendixlabs/mxcli/sdk/mpr"
@@ -154,6 +155,42 @@ func imageFormatToExt(format string) string {
154155
}
155156
}
156157

158+
// showImageCollections handles SHOW IMAGE COLLECTION [IN module].
159+
func (e *Executor) showImageCollections(moduleName string) error {
160+
collections, err := e.reader.ListImageCollections()
161+
if err != nil {
162+
return fmt.Errorf("failed to list image collections: %w", err)
163+
}
164+
165+
h, err := e.getHierarchy()
166+
if err != nil {
167+
return err
168+
}
169+
170+
fmt.Fprintf(e.output, "| %-40s | %-12s | %-6s |\n", "Image Collection", "Export Level", "Images")
171+
fmt.Fprintf(e.output, "|%-42s|%-14s|%-8s|\n", strings.Repeat("-", 42), strings.Repeat("-", 14), strings.Repeat("-", 8))
172+
173+
count := 0
174+
for _, ic := range collections {
175+
modID := h.FindModuleID(ic.ContainerID)
176+
modName := h.GetModuleName(modID)
177+
if moduleName != "" && modName != moduleName {
178+
continue
179+
}
180+
181+
qualifiedName := fmt.Sprintf("%s.%s", modName, ic.Name)
182+
exportLevel := ic.ExportLevel
183+
if exportLevel == "" {
184+
exportLevel = "Hidden"
185+
}
186+
fmt.Fprintf(e.output, "| %-40s | %-12s | %6d |\n", qualifiedName, exportLevel, len(ic.Images))
187+
count++
188+
}
189+
190+
fmt.Fprintf(e.output, "\n(%d image collection(s))\n", count)
191+
return nil
192+
}
193+
157194
// findImageCollection finds an image collection by module and name.
158195
func (e *Executor) findImageCollection(moduleName, collectionName string) *mpr.ImageCollection {
159196
collections, err := e.reader.ListImageCollections()

mdl/executor/executor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@ func (e *Executor) execShow(s *ast.ShowStmt) error {
752752
return e.showFragments()
753753
case ast.ShowDatabaseConnections:
754754
return e.showDatabaseConnections(s.InModule)
755+
case ast.ShowImageCollections:
756+
return e.showImageCollections(s.InModule)
755757
default:
756758
return fmt.Errorf("unknown show object type")
757759
}

mdl/grammar/MDLParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,6 +2408,7 @@ showStatement
24082408
| SHOW LAYOUTS (IN (qualifiedName | IDENTIFIER))?
24092409
| SHOW NOTEBOOKS (IN (qualifiedName | IDENTIFIER))?
24102410
| SHOW JAVA ACTIONS (IN (qualifiedName | IDENTIFIER))?
2411+
| SHOW IMAGE COLLECTION (IN (qualifiedName | IDENTIFIER))? // SHOW IMAGE COLLECTION [IN Module]
24112412
| SHOW ENTITY qualifiedName
24122413
| SHOW ASSOCIATION qualifiedName
24132414
| SHOW PAGE qualifiedName

mdl/grammar/parser/MDLParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)