Skip to content

Commit 6f8efe7

Browse files
committed
Implement setting project attribute via project:info
1 parent dbe0dec commit 6f8efe7

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

go-tests/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.24.4
66

77
require (
88
github.com/go-chi/chi/v5 v5.2.2
9-
github.com/platformsh/cli v0.0.0-20250512110214-68e4962f0990
9+
github.com/platformsh/cli v0.0.0-20250703103124-87b7ab372c7b
1010
github.com/stretchr/testify v1.10.0
1111
golang.org/x/crypto v0.39.0
1212
)

go-tests/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hH
55
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=
66
github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
77
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
8-
github.com/platformsh/cli v0.0.0-20250512110214-68e4962f0990 h1:0xJ3ftKO/9qB3KCMnGzEzKZizOEJgCGBfOQk1ts9szk=
9-
github.com/platformsh/cli v0.0.0-20250512110214-68e4962f0990/go.mod h1:1OFXJCFPlXT4zSc1U/U3xSNh1UmuqOm9rz+FldYe8z8=
8+
github.com/platformsh/cli v0.0.0-20250703103124-87b7ab372c7b h1:o0ykauvwRrRUKszPVLjaI2MaB9y276vlwYEaxzUfwXE=
9+
github.com/platformsh/cli v0.0.0-20250703103124-87b7ab372c7b/go.mod h1:1OFXJCFPlXT4zSc1U/U3xSNh1UmuqOm9rz+FldYe8z8=
1010
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
1111
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1212
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=

go-tests/project_info_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@ git [email protected]:mock-project.git`
8181

8282
// TODO --refresh should not be needed here
8383
assert.Equal(t, "New Title\n", f.Run("pro:info", "-p", projectID, "title", "--refresh"))
84+
85+
// Test setting an attribute using dot notation
86+
f.Run("pro:info", "-v", "-p", projectID, "attributes.foo", "bar")
87+
// TODO --refresh should not be needed here
88+
assert.Equal(t, "bar\n", f.Run("pro:info", "-p", projectID, "attributes.foo", "--refresh"))
8489
}

src/Command/Project/ProjectInfoCommand.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,16 @@ protected function listProperties(array $properties): int
113113

114114
protected function setProperty(string $property, string $value, Project $project, bool $noWait): int
115115
{
116-
$type = $this->getType($property);
116+
$isMap = str_contains($property, '.');
117+
if ($isMap) {
118+
[$mapName, $mapKey] = explode('.', $property, 2);
119+
}
120+
if ($isMap) {
121+
$type = $this->getType($mapName . '.*');
122+
} else {
123+
$type = $this->getType($property);
124+
}
125+
117126
if (!$type) {
118127
$this->stdErr->writeln("Property not writable: <error>$property</error>");
119128
return 1;
@@ -122,17 +131,28 @@ protected function setProperty(string $property, string $value, Project $project
122131
$value = false;
123132
}
124133
settype($value, $type);
125-
$currentValue = $project->getProperty($property);
134+
135+
if ($isMap) {
136+
$currentMap = $project->getProperty($mapName) ?? [];
137+
$currentValue = $currentMap[$mapKey] ?? null;
138+
} else {
139+
$currentValue = $project->getProperty($property);
140+
}
126141
if ($currentValue === $value) {
127142
$this->stdErr->writeln(
128143
"Property <info>$property</info> already set as: " . $this->propertyFormatter->format($value, $property),
129144
);
130145

131146
return 0;
147+
132148
}
133149

150+
$update = [$property => $value];
151+
if ($isMap) {
152+
$update = [$mapName => [$mapKey => $value]];
153+
}
134154
$project->ensureFull();
135-
$result = $project->update([$property => $value]);
155+
$result = $project->update($update);
136156
$this->stdErr->writeln(sprintf(
137157
'Property <info>%s</info> set to: %s',
138158
$property,
@@ -160,6 +180,7 @@ protected function getType(string $property): string|false
160180
'description' => 'string',
161181
'default_domain' => 'string',
162182
'default_branch' => 'string',
183+
'attributes.*' => 'string',
163184
];
164185

165186
return $writableProperties[$property] ?? false;

0 commit comments

Comments
 (0)