Skip to content

Commit e49ff3d

Browse files
committed
wip
1 parent e09d73d commit e49ff3d

File tree

9 files changed

+172
-47
lines changed

9 files changed

+172
-47
lines changed

desktop/src-tauri/src/types/generated/workspace.rs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,15 @@ impl ExecutableFilter {
155155
#[doc = " \"default\": [],"]
156156
#[doc = " \"$ref\": \"#/definitions/CommonTags\""]
157157
#[doc = " },"]
158-
#[doc = " \"verbAliasEnabled\": {"]
159-
#[doc = " \"description\": \"If true, the executables in the workspace can be referred to by their verb aliases.\\nThis allows you to use commands like `flow run` instead of `flow exec`.\\n\","]
160-
#[doc = " \"type\": \"boolean\""]
158+
#[doc = " \"verbAliases\": {"]
159+
#[doc = " \"description\": \"A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.\\nSetting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs.\\n\\nIf set to an empty object, verb aliases will be disabled.\\n\","]
160+
#[doc = " \"type\": \"object\","]
161+
#[doc = " \"additionalProperties\": {"]
162+
#[doc = " \"type\": \"array\","]
163+
#[doc = " \"items\": {"]
164+
#[doc = " \"type\": \"string\""]
165+
#[doc = " }"]
166+
#[doc = " }"]
161167
#[doc = " }"]
162168
#[doc = " }"]
163169
#[doc = "}"]
@@ -178,13 +184,14 @@ pub struct Workspace {
178184
pub executables: ::std::option::Option<ExecutableFilter>,
179185
#[serde(default = "defaults::workspace_tags")]
180186
pub tags: CommonTags,
181-
#[doc = "If true, the executables in the workspace can be referred to by their verb aliases.\nThis allows you to use commands like `flow run` instead of `flow exec`.\n"]
187+
#[doc = "A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.\nSetting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs.\n\nIf set to an empty object, verb aliases will be disabled.\n"]
182188
#[serde(
183-
rename = "verbAliasEnabled",
189+
rename = "verbAliases",
184190
default,
185-
skip_serializing_if = "::std::option::Option::is_none"
191+
skip_serializing_if = ":: std :: collections :: HashMap::is_empty"
186192
)]
187-
pub verb_alias_enabled: ::std::option::Option<bool>,
193+
pub verb_aliases:
194+
::std::collections::HashMap<::std::string::String, ::std::vec::Vec<::std::string::String>>,
188195
}
189196
impl ::std::convert::From<&Workspace> for Workspace {
190197
fn from(value: &Workspace) -> Self {
@@ -199,7 +206,7 @@ impl ::std::default::Default for Workspace {
199206
display_name: Default::default(),
200207
executables: Default::default(),
201208
tags: defaults::workspace_tags(),
202-
verb_alias_enabled: Default::default(),
209+
verb_aliases: Default::default(),
203210
}
204211
}
205212
}
@@ -276,8 +283,13 @@ pub mod builder {
276283
::std::string::String,
277284
>,
278285
tags: ::std::result::Result<super::CommonTags, ::std::string::String>,
279-
verb_alias_enabled:
280-
::std::result::Result<::std::option::Option<bool>, ::std::string::String>,
286+
verb_aliases: ::std::result::Result<
287+
::std::collections::HashMap<
288+
::std::string::String,
289+
::std::vec::Vec<::std::string::String>,
290+
>,
291+
::std::string::String,
292+
>,
281293
}
282294
impl ::std::default::Default for Workspace {
283295
fn default() -> Self {
@@ -287,7 +299,7 @@ pub mod builder {
287299
display_name: Ok(Default::default()),
288300
executables: Ok(Default::default()),
289301
tags: Ok(super::defaults::workspace_tags()),
290-
verb_alias_enabled: Ok(Default::default()),
302+
verb_aliases: Ok(Default::default()),
291303
}
292304
}
293305
}
@@ -345,17 +357,19 @@ pub mod builder {
345357
.map_err(|e| format!("error converting supplied value for tags: {}", e));
346358
self
347359
}
348-
pub fn verb_alias_enabled<T>(mut self, value: T) -> Self
360+
pub fn verb_aliases<T>(mut self, value: T) -> Self
349361
where
350-
T: ::std::convert::TryInto<::std::option::Option<bool>>,
362+
T: ::std::convert::TryInto<
363+
::std::collections::HashMap<
364+
::std::string::String,
365+
::std::vec::Vec<::std::string::String>,
366+
>,
367+
>,
351368
T::Error: ::std::fmt::Display,
352369
{
353-
self.verb_alias_enabled = value.try_into().map_err(|e| {
354-
format!(
355-
"error converting supplied value for verb_alias_enabled: {}",
356-
e
357-
)
358-
});
370+
self.verb_aliases = value
371+
.try_into()
372+
.map_err(|e| format!("error converting supplied value for verb_aliases: {}", e));
359373
self
360374
}
361375
}
@@ -370,7 +384,7 @@ pub mod builder {
370384
display_name: value.display_name?,
371385
executables: value.executables?,
372386
tags: value.tags?,
373-
verb_alias_enabled: value.verb_alias_enabled?,
387+
verb_aliases: value.verb_aliases?,
374388
})
375389
}
376390
}
@@ -382,7 +396,7 @@ pub mod builder {
382396
display_name: Ok(value.display_name),
383397
executables: Ok(value.executables),
384398
tags: Ok(value.tags),
385-
verb_alias_enabled: Ok(value.verb_alias_enabled),
399+
verb_aliases: Ok(value.verb_aliases),
386400
}
387401
}
388402
}

desktop/src/types/generated/workspace.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ export interface Workspace {
3232
executables?: ExecutableFilter;
3333
tags?: CommonTags;
3434
/**
35-
* If true, the executables in the workspace can be referred to by their verb aliases.
36-
* This allows you to use commands like `flow run` instead of `flow exec`.
35+
* A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.
36+
* Setting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs.
37+
*
38+
* If set to an empty object, verb aliases will be disabled.
3739
*
3840
*/
39-
verbAliasEnabled?: boolean;
41+
verbAliases?: {
42+
[k: string]: string[];
43+
};
4044
[k: string]: unknown;
4145
}
4246
export interface ExecutableFilter {

docs/schemas/workspace_schema.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@
5757
"$ref": "#/definitions/CommonTags",
5858
"default": []
5959
},
60-
"verbAliasEnabled": {
61-
"description": "If true, the executables in the workspace can be referred to by their verb aliases.\nThis allows you to use commands like `flow run` instead of `flow exec`.\n",
62-
"type": "boolean"
60+
"verbAliases": {
61+
"description": "A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.\nSetting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs.\n\nIf set to an empty object, verb aliases will be disabled.\n",
62+
"type": "object",
63+
"additionalProperties": {
64+
"type": "array",
65+
"items": {
66+
"type": "string"
67+
}
68+
}
6369
}
6470
}
6571
}

docs/types/workspace.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Every workspace has a workspace config file named `flow.yaml` in the root of the
1919
| `displayName` | The display name of the workspace. This is used in the interactive UI. | `string` | | |
2020
| `executables` | | [ExecutableFilter](#ExecutableFilter) | <no value> | |
2121
| `tags` | | [CommonTags](#CommonTags) | [] | |
22-
| `verbAliasEnabled` | If true, the executables in the workspace can be referred to by their verb aliases. This allows you to use commands like `flow run` instead of `flow exec`. | `boolean` | <no value> | |
22+
| `verbAliases` | A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace. Setting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs. If set to an empty object, verb aliases will be disabled. | `map` (`string` -> `array` (`string`)) | <no value> | |
2323

2424

2525
## Definitions

flow.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: |
44
Source code for flow
55
GitHub Repo: github.com/flowexec/flow
66
descriptionFile: docs/development.md
7-
verbAliasEnabled: true
7+
verbAliases: {}
88
executables:
99
excluded:
1010
- node_modules

internal/cache/executables_cache.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/flowexec/flow/internal/filesystem"
1111
"github.com/flowexec/flow/types/common"
1212
"github.com/flowexec/flow/types/executable"
13+
"github.com/flowexec/flow/types/workspace"
1314
)
1415

1516
const execCacheKey = "executables"
@@ -90,11 +91,8 @@ func (c *ExecutableCacheImpl) Update(logger io.Logger) error { //nolint:gocognit
9091
continue
9192
}
9293
cacheData.ExecutableMap[e.Ref()] = flowFile.ConfigPath()
93-
if wsCfg.VerbAliasEnabled == nil || *wsCfg.VerbAliasEnabled {
94-
// TODO: allow specifying custom alias mappings
95-
for _, ref := range enumerateExecutableAliasRefs(e) {
96-
cacheData.AliasMap[ref] = e.Ref()
97-
}
94+
for _, ref := range enumerateExecutableAliasRefs(e, wsCfg.VerbAliases) {
95+
cacheData.AliasMap[ref] = e.Ref()
9896
}
9997
cacheData.ConfigMap[flowFile.ConfigPath()] = WorkspaceInfo{
10098
WorkspaceName: wsCfg.AssignedName(),
@@ -234,13 +232,32 @@ func (c *ExecutableCacheImpl) initExecutableCacheData(logger io.Logger) error {
234232
return nil
235233
}
236234

237-
func enumerateExecutableAliasRefs(exec *executable.Executable) executable.RefList {
235+
func enumerateExecutableAliasRefs(
236+
exec *executable.Executable,
237+
override workspace.WorkspaceVerbAliases,
238+
) executable.RefList {
238239
refs := make(executable.RefList, 0)
239240

240-
for _, verb := range executable.RelatedVerbs(exec.Verb) {
241-
refs = append(refs, executable.NewRef(exec.ID(), verb))
242-
for _, id := range exec.AliasesIDs() {
243-
refs = append(refs, executable.NewRef(id, verb))
241+
if override == nil {
242+
for _, verb := range executable.RelatedVerbs(exec.Verb) {
243+
refs = append(refs, executable.NewRef(exec.ID(), verb))
244+
for _, id := range exec.AliasesIDs() {
245+
refs = append(refs, executable.NewRef(id, verb))
246+
}
247+
}
248+
} else {
249+
if verbs, found := override[exec.Verb.String()]; found {
250+
for _, v := range verbs {
251+
vv := executable.Verb(v)
252+
if err := vv.Validate(); err != nil {
253+
// If the verb is not valid, skip it
254+
continue
255+
}
256+
refs = append(refs, executable.NewRef(exec.ID(), vv))
257+
for _, id := range exec.AliasesIDs() {
258+
refs = append(refs, executable.NewRef(id, vv))
259+
}
260+
}
244261
}
245262
}
246263

internal/runner/gomock_reflect_3858569983/prog.go

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

types/workspace/schema.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ properties:
4646
type: string
4747
description: A path to a markdown file that contains the description of the workspace.
4848
default: ""
49-
verbAliasEnabled:
50-
type: boolean
49+
verbAliases:
50+
type: object
5151
description: |
52-
If true, the executables in the workspace can be referred to by their verb aliases.
53-
This allows you to use commands like `flow run` instead of `flow exec`.
52+
A map of executable verbs to valid aliases. This allows you to use custom aliases for exec commands in the workspace.
53+
Setting this will override all of the default flow command aliases. The verbs and it's mapped aliases must be valid flow verbs.
54+
55+
If set to an empty object, verb aliases will be disabled.
56+
additionalProperties:
57+
type: array
58+
items:
59+
type: string
5460
assignedName:
5561
type: string
5662
goJSONSchema:

types/workspace/workspace.gen.go

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)